Part Number Hot Search : 
FST8335L TL400G IL2902 2SC1446 2N3906 XU1004 7C102 1004X
Product Description
Full Text Search
 

To Download AN2135S Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  the ez-usb the ez-usb the ez-usb the ez-usb the ez-usb tm tm tm tm tm integrated circuit integrated circuit integrated circuit integrated circuit integrated circuit technical reference
the information in this document is subject to change without notice and should not be construed as a commitment by cypress semiconductor corporation. while reasonable precautions have been taken, cypress semiconductor corporation assumes no responsibility for any errors that may appear in this document. no part of this document may be copied or reproduced in any form or by any means without the prior written consent of cypress semiconductor corporation. cypress semiconductor corporation products are not designed, intended, or authorized for use as components in systems intended for surgical implant into the body, or other applications intended to support or sustain life, or for any other application in which the failure of the cypress semiconductor corporation product could create a situation where personal injury or death may occur. should buyer purchase or use cypress semiconductor corporation products for any such unintended or unauthorized application, buyer shall indemnify and hold cypress semiconductor corporation and its officers, employees, subsidiaries, affiliates and distributors harmless against all claims, costs, damages, expenses, and reasonable attorney fees arising out of, directly or indirectly, any claim of personal injury or death associated with such unintended or unauthorized use, even if such claim alleges that cypress semiconductor corporation was negligent regarding the design or manufacture of the part. the acceptance of this document will be construed as an acceptance of the foregoing conditions. appendices a, b, and c of this manual contain copyrighted material that is the property of synopsys, inc., ? 1998, all rights reserved. the ez-usb technical reference manual copyright 2000, cypress semiconductor corporation. all rights reserved.
development kit getting started documentation for the ez-usb? xcelerator? development it. includes an overview of the kit, descriptions of kit components with installation instruc- tions, and details about the development board. technical reference documentation of the ez-usb controller. includes details about the cpu, memory, input/output, renumeration?, bulk transfers, endpoint zero, iso- chronous transfers, interrupts, resets, power management, registers, ac/ dc parameters, and packages. appendices documentation for the 8051 enhanced core. includes an introduction, an architectural overview, and a hardware description. registers ez-usb register maps. technical support: phone: (858) 613-7929 e-mail: usbapps@cypress.com website: www.cypress.com ez-usb technical reference manual version 1.9 may 2000
ez-usb trm v1.9 table of contents i ez-usb technical reference manual table of contents tableofcontents.................................................. i figures .........................................................vii tables.......................................................... xi 1 introducing ez-usb ......................................................................1-1 1.1 introduction ............................................................................................. 1-1 1.2 ez-usb block diagrams ....................................................................... 1-2 1.3 the usb specification ........................................................................... 1-3 1.4 tokens and pids ..................................................................................... 1-4 1.5 host is master ......................................................................................... 1-5 1.5.1 receiving data from the host .................................................. 1-6 1.5.2 sending data to the host ......................................................... 1-6 1.6 usb direction ......................................................................................... 1-6 1.7 frame ...................................................................................................... 1-6 1.7.1 bulk transfers .......................................................................... 1-7 1.7.2 interrupt transfers ................................................................... 1-7 1.8 ez-usb transfer types ......................................................................... 1-7 1.8.1 isochronous transfers ............................................................. 1-8 1.8.2 control transfers ..................................................................... 1-8 1.9 enumeration ............................................................................................ 1-9 1.10 the usb core ....................................................................................... 1-10 1.11 ez-usb microprocessor ...................................................................... 1-11 1.12 renumeration ...................................................................................... 1-12 1.13 ez-usb endpoints ............................................................................... 1-12 1.13.1 ez-usb bulk endpoints ......................................................... 1-13 1.13.2 ez-usb control endpoint zero ............................................ 1-13 1.13.3 ez-usb interrupt endpoints ................................................. 1-14 1.13.4 ez-usb isochronous endpoints ............................................ 1-14 1.14 fast transfer modes ............................................................................. 1-14 1.15 interrupts ............................................................................................... 1-15
ii table of contents ez-usb trm v1.9 1.16 reset and power management .............................................................. 1-15 1.17 ez-usb product family ....................................................................... 1-16 1.18 summary of an2122, an2126 features ............................................. 1-16 1.19 revision id ........................................................................................... 1-17 1.20 pin descriptions .................................................................................... 1-18 2 ez-usb cpu .................................................................................. 2-1 2.1 introduction ............................................................................................. 2-1 2.2 8051 enhancements ................................................................................ 2-1 2.3 ez-usb enhancements .......................................................................... 2-2 2.4 ez-usb register interface ..................................................................... 2-2 2.5 ez-usb internal ram ........................................................................... 2-3 2.6 i/o ports .................................................................................................. 2-3 2.7 interrupts ................................................................................................. 2-4 2.8 power control ......................................................................................... 2-5 2.9 sfrs ........................................................................................................ 2-6 2.10 internal bus ............................................................................................. 2-7 2.11 reset ........................................................................................................ 2-7 3 ez-usb memory ............................................................................ 3-1 3.1 introduction ............................................................................................. 3-1 3.2 8051 memory .......................................................................................... 3-2 3.3 expanding ez-usb memory ................................................................. 3-4 3.4 cs# and oe# signals .............................................................................. 3-5 3.5 ez-usb rom versions ......................................................................... 3-7 4 ez-usb input/output ................................................................... 4-1 4.1 introduction ............................................................................................. 4-1 4.2 io ports ................................................................................................... 4-2 4.3 io port registers ..................................................................................... 4-5 4.4 i2c controller ......................................................................................... 4-6 4.5 8051 i2c controller ................................................................................ 4-6 4.5.1 start ...................................................................................... 4-8 4.5.2 stop ........................................................................................ 4-8 4.6 control bits ............................................................................................. 4-8 4.6.1 lastrd ................................................................................... 4-9 4.6.2 done ....................................................................................... 4-9 4.6.3 ack .......................................................................................... 4-9 4.7 status bits ............................................................................................... 4-9 4.7.1 berr ...................................................................................... 4-10
ez-usb trm v1.9 table of contents iii 4.7.2 id1, id0 ................................................................................. 4-10 4.8 sending i2c data .................................................................................. 4-10 4.9 receiving i2c data ............................................................................... 4-11 4.10 i2c boot loader ................................................................................... 4-12 5 ez-usb enumeration and renumeration ..................................5-1 5.1 introduction ............................................................................................. 5-1 5.2 the default usb device ........................................................................ 5-2 5.3 ez-usb core response to ep0 device requests .................................. 5-4 5.4 firmware load ........................................................................................ 5-5 5.5 enumeration modes ................................................................................ 5-7 5.6 no serial eeprom ................................................................................ 5-8 5.7 serial eeprom present, first byte is 0xb0 .......................................... 5-9 5.8 serial eeprom present, first byte is 0xb2 ........................................ 5-10 5.9 renumeration ...................................................................................... 5-11 5.10 multiple renumerations ..................................................................... 5-13 5.11 default descriptor ................................................................................. 5-13 6 ez-usb bulk transfers .................................................................6-1 6.1 introduction ............................................................................................. 6-1 6.2 bulk in transfers ................................................................................... 6-4 6.3 interrupt transfers .................................................................................. 6-5 6.4 ez-usb bulk in example ..................................................................... 6-5 6.5 bulk out transfers ............................................................................... 6-6 6.6 endpoint pairing ..................................................................................... 6-8 6.7 paired in endpoint status ....................................................................... 6-9 6.8 paired out endpoint status ................................................................. 6-10 6.9 using bulk buffer memory .................................................................. 6-10 6.10 data toggle control ............................................................................. 6-11 6.11 polled bulk transfer example .............................................................. 6-13 6.12 enumeration note ................................................................................. 6-14 6.13 bulk endpoint interrupts ...................................................................... 6-15 6.14 interrupt bulk transfer example .......................................................... 6-16 6.15 enumeration note ................................................................................. 6-21 6.16 the autopointer .................................................................................... 6-22 7 ez-usb endpoint zero ..................................................................7-1 7.1 introduction ............................................................................................. 7-1 7.2 control endpoint ep0 ............................................................................. 7-2 7.3 usb requests ......................................................................................... 7-5
iv table of contents ez-usb trm v1.9 7.3.1 get status ................................................................................. 7-7 7.3.2 set feature ............................................................................. 7-10 7.3.3 clear feature ......................................................................... 7-12 7.3.4 get descriptor ....................................................................... 7-12 7.3.4.1 get descriptor-device............................................................... 7-14 7.3.4.2 get descriptor-configuration.................................................... 7-15 7.3.4.3 get descriptor-string ................................................................ 7-16 7.3.5 set descriptor ........................................................................ 7-16 7.3.6 set configuration ................................................................... 7-19 7.3.7 get configuration .................................................................. 7-19 7.3.8 set interface ........................................................................... 7-20 7.3.9 get interface .......................................................................... 7-21 7.3.10 set address ............................................................................. 7-21 7.3.11 sync frame ............................................................................ 7-22 7.3.12 firmware load ...................................................................... 7-23 8 ez-usb isochronous transfers .................................................... 8-1 8.1 introduction ............................................................................................. 8-1 8.1.1 initialization ............................................................................. 8-2 8.2 isochronous in transfers ........................................................................ 8-2 8.2.1 in data transfers .................................................................... 8-3 8.3 isochronous out transfers .................................................................... 8-3 8.3.1 initialization ............................................................................. 8-4 8.3.2 out data transfer .................................................................. 8-4 8.4 setting isochronous fifo sizes ............................................................. 8-5 8.5 isochronous transfer speed .................................................................... 8-8 8.6 fast transfers .......................................................................................... 8-9 8.6.1 fast writes ............................................................................. 8-10 8.6.2 fast reads .............................................................................. 8-11 8.7 fast transfer timing ............................................................................ 8-11 8.7.1 fast write waveforms ........................................................... 8-12 8.7.2 fast read waveforms ............................................................ 8-13 8.8 fast transfer speed .............................................................................. 8-14 8.8.1 disable iso ............................................................................ 8-15 8.9 other isochronous registers ................................................................. 8-15 8.9.1 zero byte count bits .............................................................. 8-16 8.10 iso in response with no data ............................................................ 8-17 8.11 using the isochronous fifos ............................................................... 8-17 9 ez-usb interrupts ......................................................................... 9-1 9.1 introduction ............................................................................................. 9-1
ez-usb trm v1.9 table of contents v 9.2 usb core interrupts ............................................................................... 9-1 9.3 wakeup interrupt .................................................................................... 9-2 9.4 usb signaling interrupts ........................................................................ 9-4 9.5 sutok, sudav interrupts ................................................................... 9-8 9.6 sof interrupt .......................................................................................... 9-9 9.7 suspend interrupt .................................................................................... 9-9 9.8 usb reset interrupt ............................................................................ 9-9 9.9 bulk endpoint interrupts ........................................................................ 9-9 9.10 usb autovectors .................................................................................. 9-10 9.11 autovector coding ................................................................................ 9-11 9.12 i 2 c interrupt .......................................................................................... 9-13 9.13 in bulk nak interrupt - (an2122/an2126 only) ............................... 9-13 9.14 i 2 c stop complete interrupt - (an2122/an2126 only) .................... 9-15 10 ez-usb resets ..............................................................................10-1 10.1 introduction ........................................................................................... 10-1 10.2 ez-usb power-on reset (por) .......................................................... 10-1 10.3 releasing the 8051 reset ...................................................................... 10-3 10.3.1 ram download ...................................................................... 10-4 10.3.2 eeprom load ...................................................................... 10-4 10.3.3 external rom ........................................................................ 10-4 10.4 8051 reset effects ................................................................................ 10-4 10.5 usb bus reset ...................................................................................... 10-5 10.6 ez-usb disconnect ............................................................................. 10-7 10.7 reset summary ..................................................................................... 10-8 11 ez-usb power management ......................................................11-1 11.1 introduction ........................................................................................... 11-1 11.2 suspend ................................................................................................. 11-2 11.3 resume .................................................................................................. 11-3 11.4 remote wakeup .................................................................................... 11-4 12 ez-usb registers .........................................................................12-1 12.1 introduction ........................................................................................... 12-1 12.2 bulk data buffers ................................................................................. 12-3 12.3 isochronous data fifos ....................................................................... 12-4 12.4 isochronous byte counts ...................................................................... 12-6 12.5 cpu registers ....................................................................................... 12-8 12.6 port configuration ................................................................................ 12-9 12.7 input-output port registers ................................................................ 12-11
vi table of contents ez-usb trm v1.9 12.8 230-kbaud uart operation - an2122, an2126 ............................. 12-14 12.9 isochronous control/status registers ................................................. 12-14 12.10 i 2 c registers ....................................................................................... 12-16 12.11 interrupts ............................................................................................. 12-19 12.12 endpoint 0 control and status registers ............................................ 12-29 12.13 endpoint 1-7 control and status registers ......................................... 12-31 12.14 global usb registers ......................................................................... 12-37 12.15 fast transfers ...................................................................................... 12-46 12.16 setup data ........................................................................................ 12-49 12.17 isochronous fifo sizes ...................................................................... 12-50 13 ez-usb ac/dc parameters ....................................................... 13-1 13.0.1 absolute maximum ratings ................................................... 13-1 13.0.2 operating conditions ............................................................ 13-1 13.0.3 dc characteristics ................................................................ 13-1 13.1 electrical characteristics ...................................................................... 13-1 13.1.1 ac electrical characteristics ................................................ 13-2 13.1.2 general memory timing ........................................................ 13-2 13.1.3 program memory read ......................................................... 13-2 13.1.4 data memory read ................................................................ 13-2 13.1.5 data memory write ............................................................... 13-3 13.1.6 fast data write ..................................................................... 13-3 13.1.7 fast data read ...................................................................... 13-3 14 ez-usb packaging ....................................................................... 14-1 14.1 44-pin pqfp package ........................................................................... 14-1 14.2 80-pin pqfp package ........................................................................... 14-3 14.3 48-pin tqfp package ........................................................................... 14-5
ez-usb trm v1.9 list of figures vii figures figure 1-1. an2131s (44 pin) simplified block diagram .................................................. 1-2 figure 1-2. an2131q (80 pin) simplified block diagram .................................................. 1-3 figure 1-3. usb packets ...................................................................................................... 1-4 figure 1-4. two bulk transfers, in and out ..................................................................... 1-7 figure 1-5. an interrupt transfer ......................................................................................... 1-7 figure 1-6. an isochronous transfer ................................................................................... 1-8 figure 1-7. a control transfer ............................................................................................. 1-8 figure 1-8. what the sie does ........................................................................................... 1-10 figure 1-9. 80-pin pqfp package (an2131q) .................................................................. 1-18 figure 1-10. 44-pin pqfp package with port b (an2121s, an2122s, and an2131s) .... 1-19 figure 1-11. 44-pin package with data bus (an2125s, an2126s, AN2135S, and an2136) .......................................................................................................... 1-20 figure 1-12. 48-pin tqfp package (an2122t) .................................................................. 1-21 figure 1-13. 48-pin tqfp package (an2126t) .................................................................. 1-22 figure 2-1. 8051 registers .................................................................................................... 2-3 figure 3-1. ez-usb 8-kb memory map - addresses are in hexadecimal ......................... 3-1 figure 3-2. ez-usb 4-kb memory map - addresses are in hexadecimal ......................... 3-1 figure 3-3. unused bulk endpoint buf fers (shaded) used as data memory ..................... 3-3 figure 3-4. ez-usb memory map with ea=0 .................................................................... 3-4 figure 3-5. ez-usb memory map with ea=1 .................................................................... 3-6 figure 3-6. 8-kb rom, 2-kb ram version ...................................................................... 3-7 figure 3-7. 32-kb rom, 4-kb ram version .................................................................... 3-8 figure 4-1. ez-usb input/output pin ................................................................................. 4-2 figure 4-2. alternate function is an output .................................................................... 4-4 figure 4-3. alternate function is an input ........................................................................ 4-4 figure 4-4. registers associated with ports a, b, and c ................................................ 4-5 figure 4-5. general i2c transfer ......................................................................................... 4-6 figure 4-6. general fc transfer .......................................................................................... 4-7 figure 4-7. fc registers ....................................................................................................... 4-8 figure 5-1. usb control and status register ..................................................................... 5-11 figure 5-2. disconnect pin logic ....................................................................................... 5-12 figure 5-3. typical disconnect circuit (discoe=1) ........................................................ 5-12 figure 6-1. two bulk transfers, in and out .................................................................. 6-1 figure 6-2. registers associated with bulk endpoints ........................................................ 6-3 figure 6-3. anatomy of a bulk in transfer ......................................................................... 6-4 figure 6-4. anatomy of a bulk out transfer ..................................................................... 6-7 figure 6-5. bulk endpoint toggle control ........................................................................ 6-11 figure 6-6. example code for a simple (polled) bulk transfer ..................................... 6-14 figure 6-7. interrupt jump table ........................................................................................ 6-18 figure 6-8. int2 interrupt vector ...................................................................................... 6-19
viii list of figures ez-usb trm v1.9 figure 6-9. interrupt service routine (isr) for en dpoint 6-out ..................................... 6-19 figure 6-10. background program transfers endpoint 6-out data to endpoint 6-in ...... 6-20 figure 6-11. initialization routine ........................................................................................ 6-21 figure 6-12. autopointer registers ...................................................................................... 6-23 figure 6-13. use of the autopointer ..................................................................................... 6-24 figure 6-14. 8051 code to transfer external data to a bulk in buffer .............................. 6-25 figure 7-1. a usb control transfer (this one has a data stage) ..................................... 7-2 figure 7-2. the two interrupts associated with ep0 control transfers ...................... 7-3 figure 7-3. registers associated with ep0 control transfers ............................................. 7-4 figure 7-4. data flow for a get_status request .................................................................. 7-7 figure 7-5. using the setup data pointer (sudptr) for get_descriptor requests ......... 7-13 figure 8-1. ez-usb isochronous endpoints 8-15 ................................................................ 8-1 figure 8-2. isochronous in endpoint registers ................................................................... 8-2 figure 8-3. isochronous out registers ............................................................................... 8-4 figure 8-4. fifo start address format ................................................................................ 8-5 figure 8-5. assembler translates fifo sizes to addresses ................................................ 8-7 figure 8-6. 8051 code to transfer data to an isochronous fifo (in8data) ................... 8-8 figure 8-7. 8051 movx instructions ................................................................................... 8-9 figure 8-8. fast transfer, ez-usb to outside memory .................................................... 8-10 figure 8-9. fast transfer, outside memory to ez-usb .................................................... 8-11 figure 8-10. the fastxfr register controls frd# and fwr# strobes .......................... 8-11 figure 8-11. fast write timing ............................................................................................ 8-12 figure 8-12. fast read timing ............................................................................................. 8-13 figure 8-13. 8051 code to transfer 640 bytes of external data to an isochronous in fifo ............................................................................................................ 8-14 figure 8-14. isoctl register ............................................................................................. 8-15 figure 8-15. zbcout register ........................................................................................... 8-16 figure 9-1. ez-usb wakeup interrupt ................................................................................ 9-2 figure 9-2. usb interrupts ................................................................................................... 9-4 figure 9-3. the order of clearing interrupt requests is important ..................................... 9-6 figure 9-4. ez-usb interrupt registers ............................................................................... 9-7 figure 9-5. sutok and sudav interrupts ........................................................................ 9-8 figure 9-6. a start of frame (sof) packet ......................................................................... 9-9 figure 9-7. the autovector mechanism in action ............................................................. 9-12 figure 9-8. i 2 c interrupt enable bits and registers ........................................................... 9-13 figure 9-9. in bulk nak interrupt request register ........................................................ 9-14 figure 9-10. in bulk nak interrupt enable register .......................................................... 9-14 figure 9-11. i 2 c mode register ............................................................................................ 9-15 figure 9-12. i 2 c control and status register ....................................................................... 9-15 figure 9-13. i 2 c data ............................................................................................................ 9-15 figure 10-1. ez-usb resets ................................................................................................ 10-1 figure 11-1. suspend-resume control ................................................................................. 11-1 figure 11-2. ez-usb suspend sequence ............................................................................. 11-2 figure 11-3. ez-usb resume sequence ............................................................................. 11-3 figure 11-4. usb control and status register ..................................................................... 11-4
ez-usb trm v1.9 list of figures ix figure 12-1. register description format ............................................................................ 12-2 figure 12-2. bulk data buffers ............................................................................................ 12-3 figure 12-3. isochronous data fifos .................................................................................. 12-4 figure 12-4. isochronous byte counts ................................................................................. 12-6 figure 12-5. cpu control and status register ..................................................................... 12-8 figure 12-6. io port configuration registers ...................................................................... 12-9 figure 12-7. output port configuration registers ............................................................. 12-11 figure 12-8. pinsn registers ............................................................................................. 12-12 figure 12-9. output enable registers ................................................................................ 12-13 figure 12-10. 230-kbaud uart operation register .......................................................... 12-14 figure 12-11. isochronous out endpoint error register ................................................... 12-14 figure 12-12. isochronous control register ........................................................................ 12-15 figure 12-13. zero byte count register .............................................................................. 12-15 figure 12-14. i 2 c transfer registers .................................................................................... 12-16 figure 12-15. i 2 c mode register ......................................................................................... 12-18 figure 12-16. interrupt vector register ............................................................................... 12-19 figure 12-17. in/out interrupt request (irq) registers ................................................... 12-20 figure 12-18. usb interrupt request (irq) registers ........................................................ 12-21 figure 12-19. in/out interrupt enable registers ............................................................... 12-23 figure 12-20. usb interrupt enable register ...................................................................... 12-24 figure 12-21. breakpoint and autovector register .............................................................. 12-26 figure 12-22. in bulk nak interrupt request register ...................................................... 12-27 figure 12-23. in bulk nak interrupt enable register ....................................................... 12-27 figure 12-24. in/out interrupt enable registers ............................................................... 12-28 figure 12-25. port configuration registers ......................................................................... 12-29 figure 12-26. in control and status registers ..................................................................... 12-32 figure 12-27. in byte count registers ................................................................................ 12-34 figure 12-28. out control and status registers ................................................................. 12-35 figure 12-29. out byte count registers ............................................................................ 12-36 figure 12-30. setup data pointer high/low registers ........................................................ 12-37 figure 12-31. usb control and status registers ................................................................. 12-38 figure 12-32. data toggle control register ........................................................................ 12-40 figure 12-33. usb frame count high/low registers ........................................................ 12-41 figure 12-34. function address register ............................................................................. 12-42 figure 12-35. usb endpoint pairing register ..................................................................... 12-43 figure 12-36. in/out valid bits register .......................................................................... 12-44 figure 12-37. isochronous in/out endpoint valid bits register ...................................... 12-45 figure 12-38. fast transfer control register ....................................................................... 12-46 figure 12-39. auto pointer registers ................................................................................... 12-48 figure 12-40. setup data buffer ....................................................................................... 12-49 figure 12-41. setup data buffer ....................................................................................... 12-50 figure 13-1. external memory timing ................................................................................ 13-4 figure 13-2. program memory read timing ....................................................................... 13-4 figure 13-3. data memory read timing ............................................................................. 13-5 figure 13-4. data memory write timing ............................................................................ 13-5
x list of figures ez-usb trm v1.9 figure 13-5. fast transfer mode block diagram ................................................................. 13-6 figure 13-6. fast transfer read timing [mode 00] ............................................................ 13-7 figure 13-7. fast transfer write timing [mode 00] ............................................................ 13-7 figure 13-8. fast transfer read timing [mode 01] ............................................................ 13-8 figure 13-9. fast transfer write timing [mode 01] ......................................................... 13-8 figure 13-10. fast transfer read timing [mode 10] ............................................................ 13-9 figure 13-11. fast transfer write timing [mode 10] ............................................................ 13-9 figure 13-12. fast transfer read timing [mode 11] .......................................................... 13-10 figure 13-13. fast transfer write timing [mode 11] .......................................................... 13-10 figure 14-1. 44-pin pqfp package (top view) .................................................................. 14-1 figure 14-2. 44-pin pqfp package (side view) .................................................................. 14-1 figure 14-3. 44-pin pqfp package (detail view) ............................................................... 14-2 figure 14-4. 80-pin pqfp package (top view) .................................................................. 14-3 figure 14-5. 80-pin pqfp package (side view) .................................................................. 14-3 figure 14-6. 80-pin pqfp package (detail view) ............................................................... 14-4 figure 14-7. 48-pin tqfp package (side view) ................................................................. 14-5 figure 14-8. 48-pin tqfp package (top view) .................................................................. 14-5 figure 14-9. 48-pin tqfp package (detail view) ............................................................... 14-6
ez-usb trm v1.9 list of tables xi ta bles table 1-1. usb pids............................................................................................................ 1-4 table 1-2. ez-usb series 2100 family ............................................................................ 1-16 table 1-3. ez-usb series 2100 pinouts by pin function ................................................. 1-23 table 2-1. ez-usb interrupts.............................................................................................. 2-4 table 2-2. added registers and bits.................................................................................... 2-6 table 4-1. io pin functions for portxcfg=0 and portxcfg=1 .................................. 4-3 table 4-2. strap boot eeprom address lines to these values ..................................... 4-13 table 4-3. results of power-on i2c test .......................................................................... 4-14 table 5-1. ez-usb default endpoints ................................................................................ 5-2 table 5-2. how the ez-usb core handles ep0 requests when renum=0 ..................... 5-4 table 5-3. firmware download ........................................................................................... 5-5 table 5-4. firmware upload ................................................................................................ 5-6 table 5-5. ez-usb core action at power-up .................................................................... 5-7 table 5-6. ez-usb device characteristics, no serial eeprom ....................................... 5-8 table 5-7. eeprom data format for b0 load ............................................................... 5-9 table 5-8. eeprom data format for b2 load ............................................................. 5-10 table 5-9. usb default device descriptor ....................................................................... 5-13 table 5-10. usb default configuration descriptor ............................................................ 5-14 table 5-11. usb default interface 0, alternate setting 0 descriptor ................................. 5-14 table 5-12. usb default interface 0, alternate setting 1 descriptor ................................. 5-15 table 5-13. usb default interface 0, alternate setting 1, interrupt endpoint descriptor.. 5-15 table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors ...... 5-16 table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors ...... 5-17 table 5-15. usb default interface 0, alternate setting 1, isochronous endpoint descriptors ........................................................................................................ 5-18 table 5-16. usb default interface 0, alternate setting 2 descriptor ................................. 5-19 table 5-17. usb default interface 0, alternate setting 1, interrupt endpoint descriptor.. 5-19 table 5-18. usb default interface 0, alternate setting 2, bulk endpoint descriptors ...... 5-20 table 5-19. usb default interface 0, alternate setting 2, isochronous endpoint descriptors ........................................................................................................ 5-21 table 6-1. ez-usb bulk, control, and interrupt endpoints ............................................... 6-1 table 6-2. endpoint pairing bits (in the usb pair register)............................................ 6-8 table 6-3. ez-usb endpoint 0-7 bu ffer addresses.......................................................... 6-10 table 6-4. 8051 int2 interrupt vector .............................................................................. 6-16 table 6-5. byte inserted by ez-usb core at location 0x45 if aven=1 ........................ 6-16
xii list of tables ez-usb trm v1.9 table 7-1. the eight bytes in a usb setup packet .......................................................... 7-5 table 7-2. how the 8051 handles usb device requests (renum=1) ............................... 7-6 table 7-3. get status-device (remote wakeup and self-powered b its) ............................ 7-8 table 7-4. get status-endpoint (stall bits).......................................................................... 7-8 table 7-5. get status-interface........................................................................................... 7-10 table 7-6. set feature-device (set remote wakeup bit) ................................................. 7-10 table 7-7. set feature-endpoint (stall).............................................................................. 7-11 table 7-8. clear feature-device (clear remote wakeup bit) .......................................... 7-12 table 7-9. clear feature-endpoint (clear stall) ................................................................ 7-12 table 7-10. get descriptor-device ...................................................................................... 7-14 table 7-11. get descriptor-configuration ........................................................................... 7-15 table 7-12. get descriptor-string ........................................................................................ 7-16 table 7-13. set descriptor-device ....................................................................................... 7-16 table 7-14. set descriptor-configuration............................................................................ 7-17 table 7-15. set descriptor-string......................................................................................... 7-17 table 7-16. set configuration .............................................................................................. 7-19 table 7-17. get configuration ............................................................................................. 7-19 table 7-18. set interface (actua lly, set alternate setting as for interface if) .................. 7-20 table 7-19. get interface (actually, get alternate setting as for interface if) ................. 7-21 table 7-20. sync frame ....................................................................................................... 7-22 table 7-21. firmware download ......................................................................................... 7-23 table 7-22. firmware upload .............................................................................................. 7-23 table 8-1. isochronous endpoint fifo starting address registers .................................... 8-6 table 8-2. addresses for rd# and wr# vs. isodisab bit.............................................. 8-15 table 9-1. ez-usb interrupts .............................................................................................. 9-1 table 9-2. 8051 jump instruction ..................................................................................... 9-10 table 9-3. a typical usb jump table .............................................................................. 9-11 table 10-1. ez-usb states after power-on reset (por) .................................................. 10-2 table 10-2. ez-usb states after a usb bus reset ............................................................ 10-6 table 10-3. effects of an ez-usb disconnect and re-connect .......................................... 10-7 table 10-4. effects of various ez-usb resets (u means un affected)....................... 10-8 table 12-1. bulk endpoint buffer memory addresses........................................................ 12-3 table 12-2. isochronous endpoint fifo register addresses .............................................. 12-4 table 12-3. isochronous endpoint byte count register addresses .................................... 12-6 table 12-4. io pin alternate functions ............................................................................. 12-10 table 12-5. control and status register addresses for endpoints 0-7.............................. 12-31 table 12-6. isochronous fifo start address registers..................................................... 12-51 table 13-1. dc characteri stics ............................................................................................ 13-1 table 13-2. general memory timing .................................................................................. 13-2
ez-usb trm v1.9 list of tables xiii table 13-3. program memory read..................................................................................... 13-2 table 13-4. data memory read ........................................................................................... 13-2 table 13-5. data memory write .......................................................................................... 13-3 table 13-6. fast data write ................................................................................................. 13-3 table 13-7. fast data read .................................................................................................. 13-3
xiv list of tables ez-usb trm v1.9
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-1 1 introducing ez-usb like a well designed automobile or appliance, a usb peripherals outward simplicity hides internal complexity. theres a lot going on under the hood of a usb device, which gives the user a new level of convenience. for example: ? a usb device can be plugged in anytime, even when the pc is turned on. ? when the pc detects that a usb device has been plugged in, it automatically inter- rogates the device to learn its capabilities and requirements. from this informa- tion, the pc automatically loads the devices driver into the operating system. when the device is unplugged, the operating system automatically logs it off and unloads its driver. ? usb devices do not use dip switches, jumpers, or configuration programs. there is never an irq, dma, memory, or io conflict with a usb device. ? usb expansion hubs make the bus available to dozens of devices. ? usb is fast enough for printers, cd-quality audio, and scanners. usb is defined in the universal serial bus specification version 1.1 ( http://usb.org ), a 268-page document that describes all aspects of a usb device in elaborate detail. this ez-usb technical reference manual describes the ez-usb chip along with usb topics that should provide help in understanding the specification. the cypress semiconductor ez-usb is a compact integrated circuit that provides a highly integrated solution for a usb peripheral device. three key ez-usb features are: ? the ez-usb family provides a soft (ram-based) solution that allows unlimited configuration and upgrades. ? the ez-usb family delivers full usb throughput. designs that use ez-usb are not limited by number of endpoints, buffer sizes, or transfer speeds. ? the ez-usb family does much of the usb housekeeping in the ez-usb core, simplifying code and accelerating the usb learning curve. 1.1 introduction
page 1-2 chapter 1. introducing ez-usb ez-usb trm v1.9 this chapter introduces some key usb concepts and terminology that should make read- ing the rest of this technical reference manual easier. figure 1-1. an2131s (44 pin) simplified block diagram the cypress semiconductor ez-usb chip packs the intelligence required by a usb peripheral interface into a compact integrated circuit. as figure 1-1 illustrates, an inte- grated usb transceiver connects to the usb bus pins d+ and d-. a serial interface engine (sie) decodes and encodes the serial data and performs error correction, bit stuff- ing, and other signaling-level details required by usb, and ultimately transfers data bytes to and from the usb interface. the internal microprocessor is enhanced 8051 with fast execution time and added fea- tures. it uses internal ram for program and data storage, making the ez-usb family a soft solution. the usb host downloads 8051 program code and device personality into ram over the usb bus, and then the ez-usb chip re-connects as the custom device as defined by the loaded code. the ez-usb family uses an enhanced sie/usb interface (called the usb core) which has the intelligence to function as a full usb device even before the 8051. the enhanced core simplifies 8051 code by implementing much of the usb protocol itself. ez-usb chips operate at 3.3v. this simplifies the design of bus-powered usb devices, since the 5v power available in the usb connector (which the usb specification allows to be as low as 4.4v) can drive a 3.3v regulator to deliver clean isolated power to the ez- usb chip. 1.2 ez-usb block diagrams serial interface engine (sie) usb transceiver +5v gnd d+ d- usb connector bytes bytes io ports general purpose microprocessor usb interface program & data ram ez-usb
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-3 figure 1-2. an2131q (80 pin) simplified block diagram figure 1-2 illustrates the an2131q, an 80-pin version of the ez-usb family. in addition to the 24 io pins, it contains a 16-bit address bus and an 8-bit data bus for external mem- ory expansion. aspecial fast transfer mode moves data directly between external logic and internal usb fifos. the fast transfer mode, along with abundant endpoint resources, allows the ez- usb family to support transfer bandwidths beyond the maximum required by the univer- sal serial bus specification version 1.1 . the universal serial bus specification version 1.1 is available on the internet at http:// usb.org . published in january 1998, the specification is the work of a founding commit- tee of seven industry heavyweights: compaq, dec, ibm, intel, microsoft, nec, and northern telecom. this impressive list of implementers secures usb as the low to medium speed pc connection method of the future. a glance at the usb specification makes it immediately apparent that usb is not nearly as simple as the customary serial or parallel port. the specification uses new terms like endpoint, isochronous, and enumeration, and finds new uses for old terms like con- figuration, interface, and interrupt. woven into the usb fabric is a software abstrac- tion model that deals with things such as pipes. the specification also contains detail about the connector types and wire colors. 1.3 the usb specification serial interface engine (sie) usb transceiver +5v gnd d+ d- usb connector bytes bytes io ports address bus data bus external memory, fifos, etc. general purpose microprocessor usb interface program & data ram ez-usb
page 1-4 chapter 1. introducing ez-usb ez-usb trm v1.9 in this manual, you will read statements like, when the host sends an in token... or the device responds with an ack. what do these terms mean? a usb transaction consists of data packets identified by special codes called packet ids or pids. a pid signifies what kind of packet is being transmitted. there are four pid types, as shown in table 1-1. figure 1-3. usb packets figure 1-3 illustrates a usb transfer. packet j is an out token, indicated by the out pid. the out token signifies that data from the host is about to be transmitted over the bus. packet !k contains data, as indicated by the data1 pid. packet l is a handshake packet, sent by the device using the ack (acknowledge) pid to signify to the host that the device received the data error-free. continuing with figure 1-3, a second transaction begins with another out token m , fol- lowed by more data n , this time using the data0 pid. finally, the device again indicates success by transmitting the ack pid in a handshake packet o . why two data pids, data0 and data1? its because the usb architects took error correction very seriously. as mentioned previously, the ack handshake is a signal to the host that the peripheral received data without error (the crc portion of the packet is used to detect errors). but what if a handshake packet itself is garbled in transmission? to detect this, each side, host and device maintains a data toggle bit, which is toggled between data packet transfers. the state of this internal toggle bit is compared with the 1.4 tokens and pids table 1-1. usb pids pid type pid name token data in, out, sof, setup, data0, data1 handshake ack, nak, stall special pre o u t a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt h/s pkt 1 2 3 4 5 6
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-5 pid that arrives with the data, either data0 or data1. when sending data, the host or device sends alternating data0-data1 pids. by comparing the data pid with the state of the internal toggle bit, the host or device can detect a corrupted handshake packet. setup tokens are unique to control transfers. they preface eight bytes of data from which the peripheral decodes host device requests. sof tokens occur once per millisecond, denoting a usb frame . there are three handshake pids: ack, nak, and stall. ? ack means success; the data was received error-free. ? nak means busy, try again. its tempting to assume that nak means error, but it doesnt. a usb device indicates an error by not responding . ? stall means that something unforeseen went wrong (probably as a result of mis- communication or lack of cooperation between the software and firmware writers). a device sends the stall handshake to indicate that it doesnt understand a device request, that something went wrong on the peripheral end, or that the host tried to access a resource that isnt there. its like halt, but better, because usb provides a way to recover from a stall. a pre (preamble) pid precedes a low-speed (1.5 mbps) usb transmission. the ez- usb family supports high-speed (12 mbps) usb transfers only, so it ignores pre packets and the subsequent low-speed transfer. this is a fundamental usb concept. there is exactly one master in a usb system: the host computer. usb devices respond to host requests. usb devices cannot send informa- tion between themselves, as they could if usb were a peer-to-peer topology. actually, there is one case where a usb device can initiate signaling without prompting from the host. after being put into a low-power suspend mode by the host, a device can signal a remote wakeup. but thats the only way to yank the hosts chain. everything else happens because the host makes device requests and the device responds to them. theres an excellent reason for this host-centric model. the usb architects were keenly mindful of cost, and the best way to make low-cost peripherals is to put most of the smarts 1.5 host is master
page 1-6 chapter 1. introducing ez-usb ez-usb trm v1.9 into the host side, the pc. if usb had been defined as peer-to-peer, every usb device would have required more intelligence, raising cost. here are two important consequences of the host is master concept: 1.5.1 receiving data from the host to send data to a usb peripheral, the host issues an out token followed by the data. if the peripheral has space for the data, and accepts it without error, it returns an ack to the host. if it is busy, it instead sends a nak. if it finds an error, it sends nothing back. for the latter two cases, the host re-sends the data at a later time. 1.5.2 sending data to the host a usb device never spontaneously sends data to the host. nevertheless, in the ez-usb chip, theres nothing to stop the 8051 from loading data for the host into an endpoint buffer (section 1.13, "ez-usb endpoints") and arming it for transfer. but the data will sit in the buffer until the host sends an in token to that particular endpoint . if the host never sends the in token, the data sits there indefinitely. once you accept that the host is the bus master, its easy to remember usb direction: out means from the host to the device, and in means from the device to the host. ez-usb nomenclature uses this naming convention. for example, an endpoint that sends data to the host is an in endpoint. this can be confusing at first, because the 8051 sends data by loading an in endpoint buffer, but keeping in mind that an 8051 out is in to the host, it makes sense. the usb host provides a time base to all usb devices by transmitting a sof (start of frame) packet every millisecond. the sof packet includes an incrementing, 11-bit frame count. the 8051 can read this frame count from two ez-usb registers. sof-time has significance for isochronous endpoints; its the time that the ping-ponging buffers switch places. the ez-usb core provides the 8051 with an sof interrupt request for servicing isochronous endpoint data. 1.6 usb direction 1.7 frame
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-7 usb defines four transfer types. these match the requirements of different data types delivered over the bus. (section 1.13, "ez-usb endpoints" explains how the ez-usb family supports the four transfer types.) 1.8.1 bulk transfers figure 1-4. two bulk transfers, in and out bulk data is bursty , traveling in packets of 8, 16, 32, or 64 bytes. bulk data has guaranteed accuracy, due to an automatic re-try mechanism for erroneous data. the host schedules bulk packets when there is available bus time. bulk transfers are typically used for printer, scanner, or modem data. bulk data has built-in flow control provided by handshake pack- ets. 1.8.2 interrupt transfers figure 1-5. an interrupt transfer interrupt data is like bulk data, but exists only for in endpoints in the universal serial bus specification version 1.1. interrupt data can have packet sizes of 1-64 bytes. inter- rupt endpoints have an associated polling interval that ensures that they will be pinged (will receive an in token) by the host on a regular basis. 1.8 ez-usb transfer types i n a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt h/s pkt i n a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k h/s pkt
page 1-8 chapter 1. introducing ez-usb ez-usb trm v1.9 1.8.3 isochronous transfers figure 1-6. an isochronous transfer isochronous data is time-critical and used for streaming data like audio and video. time of delivery is the most important requirement for isochronous data. in every usb frame, a certain amount of usb bandwidth is allocated to isochronous transfers. to lighten the overhead, isochronous transfers have no handshake (ack/nak/stall), and no retries. error detection is limited to a 16-bit crc. isochronous transfers do not use the data tog- gle mechanism; isochronous data uses only the data0 pid. 1.8.4 control transfers figure 1-7. a control transfer control transfers are used to configure and send commands to a device. being mission critical , they employ the most extensive error checking usb offers. control transfers are delivered on a best effort basis by the host ( best effort is defined by a six-step process in the universal serial bus specification version 1.1, section 5.5.4 ). the host reserves a part of each usb frame time for control transfers. i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet i n a d d r e n d p c r c 5 token packet d a t a 0 8bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k h/s pkt d a t a 1 o u t a d d r e n d p c r c 5 token packet c r c 1 6 data pkt a c k h/s pkt setup stage data stage (optional) status stage
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-9 control transfers consist of two or three stages. the setup stage contains eight bytes of usb control data. an optional data stage contains more data, if required. the status (or handshake ) stage allows the device to indicate successful completion of a control operation. your computer is on. you plug in a usb device, and the windows ? cursor switches to an hourglass, and then back to a cursor. and magically, your device is connected and its windows ? driver is loaded! anyone who has installed a sound card into a pc and had to configure countless jumpers, drivers, and io/interrupt/dma settings knows that a usb connection can be like a miracle. weve all heard about plug and play, but usb delivers the real thing. how does all this happen automatically? inside every usb device is a table of descrip- tors that are the sum total of the devices requirements and capabilities. when you plug into usb, the host goes through a sign-on sequence: 1. the host sends a get_descriptor/device request to address zero (devices must respond to address zero when first attached). 2. the device dutifully responds to this request by sending id data back to the host telling what it is. 3. the host sends the device a set_address request, which gives it a unique address to distinguish it from the other devices connected to the bus. 4. the host sends more get_descriptor requests, asking more device information. from this, it learns everything else about the device, like how many endpoints the device has, its power requirements, what bus bandwidth it requires, and what driver to load. this sign-on process is called enumeration . 1.9 enumeration
page 1-10 chapter 1. introducing ez-usb ez-usb trm v1.9 figure 1-8. what the sie does every usb device has a serial interface engine (sie). the sie connects to the usb data lines d+ and d-, and delivers bytes to and from the usb device. figure 1-8 illustrates a usb bulk transfer, with time moving from left to right. the sie decodes the packet pids, performs error checking on the data using the transmitted crc bits, and delivers payload data to the usb device. if the sie encounters an error in the data, it automatically indi- cates no response instead of supplying a handshake pid. this instructs the host to re- transmit the data at a later time. bulk transfers such as the one illustrated in figure 1-8 are asynchronous , meaning that they include a flow control mechanism using ack and nak handshake pids. the sie indicates busy to the host by sending a nak handshake packet. when the peripheral device has successfully transferred the data, it commands the sie to send an ack hand- shake packet, indicating success. to send data to the host, the sie accepts bytes and control signals from the usb device, formats it for usb transfer, and sends it over the two-wire usb. because the usb uses a self-clocking data format (nrzi), the sie also inserts bits at appropriate places in the bit stream to guarantee a certain number of transitions in the serial data. this is called bit stuffing, and is transparently handled by the sie. 1.10 the usb core serial interface engine (sie) d+ d- usb tranceiver o u t a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt payload data payload data a c k h/s pkt
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-11 one of the most important features of the ez-usb family is that it is soft . instead of requiring rom or other fixed memory, it contains internal program/data ram that is downloaded over the usb itself to give the device its unique personality. this make mod- ifications, specification revisions, and updates a snap. the ez-usb family can connect as a usb device and download code into internal ram, all while its internal 8051 is held in reset. this is done by an enhanced sie, which does all of the work shown in figure 1-8, and more. it contains additional logic to perform a full enumeration, using an internal table of descriptors. it also responds to a vendor spe- cific firmware download device request to load its internal ram. an added bonus is that the added sie functionality is also made available to the 8051. this saves 8051 code and processing time. throughout this manual, the sie and its enhancements are referred to as the usb core. the ez-usb microprocessor is an enhanced 8051 core. use of an 8051 compatible pro- cessor makes extensive software support tools immediately available to the ez-usb designer. this enhanced 8051 core, described in chapter 2, "ez-usb cpu" and appen- dices a-c, has the following features: ? 4-clock cycle, as compared to the 12-clock cycle of a standard 8051, giving a 3x speed improvement. ? dual data pointers for faster memory-to-memory transfers. ? two uarts. ? three counter-timers. ? an expanded interrupt system. ? 24-mhz clock. ? 256 bytes of internal register ram. ? standard 8051 instruction setif you know the 8051, you know ez-usb the enhanced 8051 core uses on-chip ram as program and data memory, giving ez-usb its soft feature. chapter 3, "ez-usb memory" describes the various memory options. 1.11 ez-usb microprocessor
page 1-12 chapter 1. introducing ez-usb ez-usb trm v1.9 the 8051 communicates with the sie using a set of registers, which occupy the top of the on-chip ram address space. these registers are grouped and described by function in individual chapters of this reference manual, and summarized in register order in chapter 12, "ez-usb registers." the ez-usb 8051 has two duties. first, it participates in the protocol defined in the uni- versal serial bus specification version 1.1, chapter 9, usb device framework. thanks to ez-usb enhancements to the sie and usb interface, the 8051 firmware asso- ciated with usb overhead is simplified, leaving code space and bandwidth available for the 8051s primary duty, to help implement your device. on the device side, abundant input/output resources are available, including io ports, uarts, and an i 2 c bus master controller. these resources are described in chapter 4, "ez-usb input/output." because it is soft , the ez-usb chip can take on the identities of multiple distinct usb devices. the first device downloads your 8051 firmware and usb descriptor tables over the usb cable when the peripheral device is plugged in. once downloaded, another device comes on as a totally different usb peripheral as defined by the downloaded infor- mation. this two-step process, called renumeration ? , happens instantly when the device is plugged in, with no hint that the initial load step has occurred. chapter 5, "ez-usb enumeration and renumeration" describes this feature in detail, along with other ez-usb boot (startup) modes. the universal serial bus specification version 1.1 defines an endpoint as a source or sink of data. since usb is a serial bus, a device endpoint is actually a fifo which sequentially empties/fills with usb bytes. the host selects a device endpoint by sending a 4-bit address and one direction bit. therefore, usb can uniquely address 32 endpoints, in0 through in15 and out0 through out15. from the ez-usb point of view, an endpoint is a buffer full of bytes received or to be transmitted over the bus. the 8051 reads endpoint data from an out buffer, and writes endpoint data for transmission over usb to an in buffer. four usb endpoint types are defined as: bulk, control, interrupt, and isochronous. 1.12 renumeration ? 1.13 ez-usb endpoints
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-13 1.13.1 ez-usb bulk endpoints bulk endpoints are unidirectionalone endpoint address per direction. therefore end- point 2-in is addressed differently than endpoint 2-out. bulk endpoints use maximum packet sizes (and therefore buffer sizes) of 8, 16, 32, or 64 bytes. ez-usb provides four- teen bulk endpoints, divided into seven in endpoints (endpoint 1-in through 7-in), and seven out endpoints (endpoint 1-out through 7-out). each of the fourteen endpoints has a 64-byte buffer. bulk data is available to the 8051 in ram form, or as fifo data using a special ez-usb autopointer (chapter 6, "ez-usb bulk transfers"). 1.13.2 ez-usb control endpoint zero control endpoints transfer mission-critical control information to and from the usb device. the universal serial bus specification version 1.1 requires every usb device to have a default control endpoint, endpoint zero. device enumeration, the process that the host initiates when the device is first plugged in, is conducted over endpoint zero. the host sends all usb requests over endpoint zero. control endpoints are bi-directional; if you have an endpoint 0 in control endpoint, you automatically have an endpoint 0 out endpoint. control endpoints alone accept setup pids. a control transfer consists of a two or three stage sequence: ?setup ? data (if needed) ? handshake eight bytes of data in the setup portion of the control transfer have special usb significance, as defined in the universal serial bus specification version 1.1, chapter 9. a usb device must respond properly to the requests described in this chapter to pass usb compliance testing (usually referred to as the usb chapter nine test). endpoint zero is the only control endpoint in the ez-usb chip. the 8051 responds to device requests issued by the host over endpoint zero. the ez-usb core is significantly enhanced to simplify the 8051 code required to service these requests. chapter 7, "ez- usb endpoint zero" provides a detailed roadmap for writing usb chapter 9 compliant 8051 code.
page 1-14 chapter 1. introducing ez-usb ez-usb trm v1.9 1.13.3 ez-usb interrupt endpoints interrupt endpoints are almost identical to bulk endpoints. fourteen ez-usb endpoints (ep1-ep7, in, and out) may be used as interrupt endpoints. interrupt endpoints have maximum packet sizes up to 64, and contain a polling interval byte in their descriptor to tell the host how often to service them. the 8051 transfers data over interrupt endpoints in exactly the same way as for bulk endpoints. interrupt endpoints are described in chapter 6, "ez-usb bulk transfers." 1.13.4 ez-usb isochronous endpoints isochronous endpoints deliver high bandwidth, time critical data over usb. isochronous endpoints are used to stream data to devices such as audio dacs, and from devices such as cameras and scanners. time of delivery is the most critical requirement, and isochro- nous endpoints are tailored to this requirement. once a device has been granted an isoch- ronous bandwidth slot by the host, it is guaranteed to be able to send or receive its data every frame. ez-usb contains 16 isochronous endpoints, numbered 8-15 (8in-15in, and 8out- 15out). 1,024 bytes of fifo memory are available to the 16 endpoints, and may be fifo memory to provide double-buffering. using double buffering, the 8051 reads out data from isochronous endpoint fifos containing data from the previous frame while the host writes current frame data into the other buffer. similarly, the 8051 loads in data into isochronous endpoint fifos that will be transmitted over usb during the next frame while the host reads current frame data from the other buffer. at every sof the usb fifos and 8051 fifos switch, or ping-pong . isochronous transfers are described in chapter 8, "ez-usb isochronous transfers." the following versions of the ez-usb have a fast transfer mode: an2125sc, an2126sc, AN2135Sc, an2136sc, and an2131qc, that is, those versions that have a data bus (see table 1-2). the fast transfer mode minimizes the transfer time from ez-usb core also supplies external fifo read and write strobes to synchronize the transfers. using the fast transfer mode, the 8051 transfers a byte of data between an internal fifo and the external bus using a single 8051 movx instruction, which takes two cycles or 333 ns. both isochronous and bulk endpoints can use this fast transfer mode. 1.14 fast transfer modes
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-15 the ez-usb enhanced 8051 adds seven interrupt sources to the standard 8051 interrupt system. three of the added interrupts are used internally, and the others are available on device pins. int2 is used for all usb interrupts. int3 is used by the i 2 cinterface. a third interrupt is used for remote wakeup indication. the ez-usb core automatically supplies jump vectors (autovectors) for its usb inter- rupts to save the 8051 from having to test bits to determine the source of the interrupt. each bulk/control/interrupt endpoint has its own vector, so when an endpoint requires service, the proper interrupt service routine is automatically invoked. the 8051 services all isochronous endpoints in response to a sof (start of frame) interrupt request. chapter 9, "ez-usb interrupts" describes the ez-usb interrupt system. the ez-usb chip contains four resets: ? power-on-reset (por) ? usb bus reset ? 8051 reset ? usb disconnect/re-connect the functions of the various ez-usb resets are described in chapter 10, "ez-usb resets." a usb peripheral may be put into a low power state when the host signals a suspend oper- ation. the universal serial bus specification version 1.1 states that a bus powered device cannot draw more than 500 u a of current from the vcc wire while in suspend. the ez- usb chip contains logic to turn off its internal oscillator and enter a sleep state. a special interrupt, triggered by a wakeup pin or wakeup signaling on the usb bus, starts the oscil- lator and interrupts the 8051 to resume operation. low power operation is described in chapter 11, "ez-usb power management." 1.15 interrupts 1.16 reset and power management
page 1-16 chapter 1. introducing ez-usb ez-usb trm v1.9 the ez-usb family is available in various pinouts to serve different system requirements and costs. table 1-2 shows the feature set for each member of the ez-usb series 2100 family. this section summarizes the features of the an2122 and an2126 packages. these fea- tures are not available in the other packages of the ez-usb family. power saving option to reduce power, the 8051 processor can be run at half speed. when the cpu12mhz pin is tied high, the 8051 processor core runs at 12 mhz. when tied low, the 8051 runs at the normal 24 mhz. the logic state of this pin should never be changed while the 8051 is running. 230 kbaud uart operation two control bits in a register, uart230, allow 230-kbaud operation by uart0 and uart1 (see section 12.8, "230-kbaud uart operation - an2122, an2126"). 1.17 ez-usb product family table 1-2. ez-usb series 2100 family part number ram size key features package max uart (async) speed (kbaud) power saving option ibn/ stop iso support endpoints data bus or port b i/o rate bytes/s max prog i/os an2121s 4kb y 32 port b 600k 16 s = 44 pqfp 115.2 n n an2122s 4kb n 13 port b 600k 16 s = 44 pqfp 230.4 n y an2122t 4kb n 13 port b 600k 19 t = 48 tqfp 230.4 y y an2125s 4kb y 32 data bus 2m 8 s = 44 pqfp 115.2 n n an2126s 4kb n 13 data bus 2m 8 s = 44 pqfp 230.4 n y an2126t 4kb n 13 data bus 2m 11 t = 48 tqfp 230.4 y y an2131q 8kb y 32 both 2m 24 q = 80 pqfp 115.2 n n an2131s 8kb y 32 port b 600k 16 s = 44 pqfp 115.2 n n AN2135S 8kb y 32 data bus 2m 8 s = 44 pqfp 115.2 n n an2136s 8kb n 16 data bus 2m 8 s = 44 pqfp 115.2 n n 1.18 summary of an2122, an2126 features
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-17 48-pin variants there are two 48-pin devices: an2122t an2126t the four extra pins are used as follows: ? pa7, pa6, and pa0 are gpio pins. this makes five of the eight porta pins available (all except pa1-pa3). ? cpu12mhz - this input controls the speed of the 8051: - tied high 12 mhz - tied low 24 mhz bulk endpoints the an2122 and an2126 have a reduced set of thirteen bulk endpoints (see section 6.1, "introduction"). interrupts the an2122 and an2126 contain two interrupts not present in the other an21xx family members. ? an ibn (in-bulk nak) interrupt request activates when an in packet is nakd by the sie because the 8051 has not loaded the buffer (and byte count register) for an in endpoint. this is useful for applications that need to know when the host is pinging an in endpoint (see section 9.13, "in bulk nak interrupt - (an2122/ an2126 only)"). ?ani 2 c interrupt source is added to the i 2 c interrupt (int3), indicating that trans- mission of a stop bit is complete (see section 9.14, "i 2 c stop complete inter- rupt - (an2122/an2126 only)"). the revision id for each part is shown in table 1.2. the revision value is reported in the internal did (device id), which is the value read by the host during enumeration if no eeprom is connected to the i 2 c bus. this value also appears in the cpucs register bits. 1.19 revision id
page 1-18 chapter 1. introducing ez-usb ez-usb trm v1.9 figures 1-9 through 1-13 are pin descriptions by package type. table 1-3 describes the pins by pin function. figure 1-9. 80-pin pqfp package (an2131q) 1.20 pin descriptions 40 38 37 36 35 34 33 32 31 30 29 28 27 26 25 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 80 pqfp 14x20mm sda gnd vcc bkpt d7 d6 d5 d4 gnd pb7/t2out pb6/int6 pb5/int5# pb4/int4 d3 d2 d1 d0 pb3/txd1 pb2/rxd1 pb1/t2ex pb0/t2 gnd vcc pc7/rd# pc0/rxd0 pc1/txd0 pc2/int0# pc3/int1# pc4/t0 pc6/wr# a8 a9 a15 a14 a13 a12 a11 a10 pc5/t1 reset scl wakeup# gnd usbd+ pa0/t0out pa1/t1out pa2/oe# pa3/cs# pa4/fwr# pa5/frd# pa6/rxd0out pa7/rxd1out nc usbd- psen# gnd 123456789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 64 63 62 61 39 gnd a6 a7 gnd agnd xin xou t avcc vcc gnd ea discon# vcc gnd clk24 gnd gnd a0 a1 a2 a3 a4 a5 gnd
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-19 figure 1-10. 44-pin pqfp package with port b (an2121s, an2122s, and an2131s) gnd reset vcc pc0/rxd0 pc1/txd0 pc2/int0# pc3/int1# pc4/t0 pc6/w r# pc7/rd # pc5/t1 avcc xout xin agnd gnd vcc clk24 gnd gnd gnd gnd gnd pb1/t2ex pb2/rxd2 pb3/txd2 pb4/int4 pb5/int5# pb6/int6 pb0/t2 vcc pb7/t2out bkpt scl sda gnd vcc wakeup# discon# usbd+ pa4/fw r# pa5/frd# gnd usbd- 12 13 14 15 16 17 20 18 19 21 22 44 43 42 41 40 39 36 38 37 35 34 33 32 31 30 29 28 25 27 26 24 23 1 2 3 4 5 6 9 7 8 10 11 44 pqfp 10x10mm
page 1-20 chapter 1. introducing ez-usb ez-usb trm v1.9 figure 1-11. 44-pin package with data bus (an2125s, an2126s, AN2135S, and an2136) gnd reset vcc pc0/rxd0 pc1/txd0 pc2/int0 # pc3/int1 # pc4/t0 pc6/w r # pc7/rd# pc5/t1 avcc xout xin agnd gnd vcc clk24 gnd gnd gnd gnd scl sda gnd vcc wakeup# discon# usbd+ pa4/fw r# pa5/frd# gnd usbd- gnd d1 d2 d3 d4 d5 d6 d0 vcc d7 bkpt 12 13 14 15 16 17 20 18 19 21 22 44 43 42 41 40 39 36 38 37 35 34 33 32 31 30 29 28 25 27 26 24 23 1 2 3 4 5 6 9 7 8 10 11 44 pqfp 10x10mm
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-21 figure 1-12. 48-pin tqfp package (an2122t) cpu12mhz 13 14 15 16 17 18 21 19 20 22 23 48 47 46 45 44 43 40 42 41 39 38 36 35 34 33 32 31 28 30 29 27 26 1 2 3 4 5 6 9 7 8 10 11 48 tqfp 7x7mm 12 pa7/rxd1out 25 24 37 pb3/txd1 pb4/int4 pb5/int5# pb6/int6 pb7/t2out pa0/t0out bkpt pa6/rxd0out reset vcc pc0/rxd0 pc1/txd0 pc2/int0# pc3/int1# pc4/t0 pc6/w r# pc7/rd# pc5/t1 avcc xout xin agnd gnd vcc clk24 gnd gnd gnd gnd scl sda w akeup# discon# usbd+ pa4/fw r# pa5/frd# gnd usbd- gnd pb1/t2ex pb2/rxd1 pb0/t2 vcc gnd gnd vcc analog vcc and gnd digital vcc digital gnd extra pins in 48-pin package
page 1-22 chapter 1. introducing ez-usb ez-usb trm v1.9 figure 1-13. 48-pin tqfp package (an2126t) 13 14 15 16 17 18 21 19 20 22 23 48 47 46 45 44 43 40 42 41 39 38 36 35 34 33 32 31 28 30 29 27 26 1 2 3 4 5 6 9 7 8 10 11 48 tqfp 7x7mm 12 pa7/rxd1out 25 24 37 cpu12mhz d3 d4 d5 d6 d7 pa0/t0out bkpt pa6/rxd0out reset vcc pc0/rxd0 pc1/txd0 pc2/int0# pc3/int1# pc4/t0 pc6/w r# pc7/rd# pc5/t1 avcc xout xin agnd gnd vcc clk24 gnd gnd gnd gnd scl sda w akeup# discon# usbd+ pa4/fw r# pa5/frd# gnd usbd- gnd d1 d2 d0 vcc gnd gnd vcc analog vcc and gnd digital vcc digital gnd extra pins in 48-pin package
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-23 table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description 21 10 10 11 11 avcc power n/a analog vcc . this signal provides power to the ana- log section of the chip. 18 7 7 7 7 agnd power n/a analog ground . connect to ground with as short a path as possible. 1 43 43 47 47 discon# output hi disconnect . this pin is controlled by two bits, discoe and discon. when discoe=0, the pin floats. when discoe=1, it drives. when discoe=1, the driven logic level is the inverse of the discon bit. 77 41 41 45 45 usbd i/o/z z usb d- signal . connect to the usb d- signal through a 24-ohm resistor. 79 42 42 46 46 usbd i/o/z z usb d+ signal . connect to the usb d+ pin through a 24-ohm resistor. 7-12, 15, 16, 26-29, 34-37 n/a n/a n/a n/a a0-a5, a6, a7, a8-a11, a12-a15 output 0x0000 8051 address bus . this bus is driven at all times. when the 8051 is addressing internal ram it reflects the internal address. 48-51, 57-60 n/a 24-27, 28-31 n/a 26-29, 30-33 d0-d3, d4- d7 i/o/z z 8051 data bus . this bi-directional bus is high- impedance when inactive, input for bus reads, and output for bus writes. the data bus is also used to transfer data directly to and from internal ez-usb fifos under control of the frd# and fwr# strobes. d0-d7 are active only for external bus accesses, and are driven low in suspend. 80 n/a n/a n/a n/a psen# output h program store enable . this active-low signal indi- cates a code fetch from external memory. it is active for program memory fetches above 0x1b40 when the ea pin is lo, or above 0x0000 when the ea pin is hi. 61 32 32 35 35 bkpt output 0 breakpoint . this pin goes active (high) when the 8051 address bus matches the bpaddrh/l regis- ters and breakpoints are enabled in the usbbav register (bpen=1). if the bppulse bit in the usbbav register is hi, this signal pulses high for eight 24-mhz clocks. if the bppulse bit is lo, the signal remains high until the 8051 clears the break bit (by writing 1 to it) in the usbbav register. 25 13 13 14 14 reset input n/a active high reset . resets the 8051 and the usb sie. this pin is normally tied to ground through a 10k-ohm resistor and to vcc through a 1 m f capac- itor.
page 1-24 chapter 1. introducing ez-usb ez-usb trm v1.9 24 n/a n/a n/a n/a ea input n/a external access . if this signal is active (high), the 8051 fetches code from external memory instead of the internal program ram. if ea=0, the 8051 fetches code from external memory starting at 0x1b40 (an2131). 19 8 8 9 9 xin input n/a crystal input . connect this signal to a 12-mhz series resonant, fundamental mode crystal and 22- 33-pf capacitor to gnd. this pin may also be driven by a 12-mhz clock. 20 9 9 10 10 xout output n/a crystal output. connect this signal to a 12-mhz series resonant, fundamental mode crystal and 22- 33-pf capacitor to gnd. if xin is driven by a 12- mhz clock, this pin should not be connected. 68 n/a n/a 34 34 pa0 or t0out i/o i (pa0) multiplexed pin whose function is selected by the t0out bit of the portacfg register. if t0out=0, the pin is the bi-directional i/o port bit pa0. if t0out=1, the pin is the active-high t0out signal from 8051 timer/counter0. t0out outputs a high level for one clk24 clock cycle when timer0 overflows. if timer0 is operated in mode 3 (two separate timer/counters), t0out is active when the low byte timer/counter overflows. 69 n/a n/a n/a n/a pa1 or t1out i/o i (pa1) multiplexed pin whose function is selected by the t1out bit of the portacfg register. if t1out=0, the pin is the bi-directional i/o port bit pa1. if t1out=1, the pin is the active-high t1out signal from 8051 timer-counter1 t1out outputs a high level for one clk24 clock cycle when timer1 overflows. if timer1 is operated in mode 3 (two separate timer/counters), t1out is active when the low byte timer/counter overflows. 70 n/a n/a n/a n/a pa2 or oe# i/o i (pa2) multiplexed pin whose function is selected by the oe bit of the portacfg register. if oe=0, the pin is the bi-directional i/o port pin pa2. if oe=1, the pin is an active-low output enable for external memory. if the oe# pin is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-25 71 n/a n/a n/a n/a pa3 or cs# i/o i (pa3) multiplexed pin whose function is selected by the cs bit of the portacfg register. if cs=0, the pin is the bi-directional i/o port pin pa3. if cs=1, the pin is an active-low chip select for external memory. if the cs# pin is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. 73 39 39 n/a n/a pa4 or fwr# i/o i (pa4) multiplexed pin whose function is selected by the fwr (fast write) bit of the portafcg register. if fwr=0, the pin is the bi-directional i/o port pin pa4. if fwr=1, the pin is the write strobe for an external fifo. if the fwr# pin is used, it should be exter- nally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. 74 40 40 n/a n/a pa5 or frd# i/o i (pa5) multiplexed pin whose function is selected by the frd (fast read) bit of the portafcg register. if frd=0, the pin is the bi-directional i/o port pin pa5. if frd=1, the pin is the read strobe for an external fifo. if the frd# pin is used, it should be exter- nally pulled up to vcc to ensure that the write strobe is inactive (high) at power-on. 75 n/a n/a 44 44 pa6 or rxd0out i/o i (pa6) multiplexed pin whose function is selected by the rxd0out bit of the portafcg register. if rxd0out=0 (default), the pin is the bi-directional i/o port bit pa6. if rxd0out=1, the pin is the active-high rxd0out signal from 8051 uart0. if rxd0out is selected and uart0 is in mode 0, this pin provides the output data for uart0 only when it is in sync mode. otherwise, it is a 1. 76 n/a n/a 8 8 pa7 or rxd1out i/o i (pa7) multiplexed pin whose function is selected by the rxd1out bit of the portafcg register. if rxd1out=0 (default), the pin is the bi-directional i/o port bit pa7. if rxd1out=1, the pin is the active-high rxd1out signal from 8051 uart1. when rxd1out is selected and uart1 is in mode 0, this pin provides the output data for uart1 only when it is in sync mode. in modes 1, 2, and 3, this pin is a 1. table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
page 1-26 chapter 1. introducing ez-usb ez-usb trm v1.9 44 24 n/a 26 n/a pb0 or t2 i/o i (pb0) multiplexed pin whose function is selected by the t2 bit of the portbfcg register. if t2=0, the pin is the bi-directional i/o port bit pb0. if t2=1, the pin is the active-high t2 signal from 8051 timer2, which pro- vides the input to timer2 when c/t2=1. when c/t2=0, timer2 does not use this pin. 45 25 n/a 27 n/a pb1 or t2ex i/o i (pb1) multiplexed pin whose function is selected by the t2ex bit of the portbcfg register. if t2ex=0, the pin is the bi-directional i/o port bit pb1. if t2ex=1, the pin is the active-high t2ex signal from 8051 timer2. 46 26 n/a 28 n/a pb2 or rxd1 i/o i (p{b2) multiplexed pin whose function is selected by the rxd1 bit of the portbcfg register. if rxd1=0, the pin is the bi-directional i/o port bit pb2. if rxd1=1, the pin is the active-high rxd1 input sig- nal for 8051 uart1, which provides data to the uart in all modes. 47 27 n/a 29 n/a pb3 or txd1 i/o i (pb3) multiplexed pin whose function is selected by the txd1 bit of the portbcfg register. if txd1=0, the pin is the bi-directional i/o port bit pb3. if txd1=1, the pin is the active-high txd1 output pin for 8051 uart1 which provides the output clock in sync mode and the output data in async mode. 52 28 n/a 30 n/a pb4 or int4 i/o i (pb4) multiplexed pin whose function is selected by the int4 bit of the portbcfg register. if int4=0, the pin is the bi-directional i/o port bit pb4. if int4=1, the pin is the 8051 int4 interrupt request signal. the int4 pin is edge-sensitive, active high. 53 29 n/a 31 n/a pb5 or int5# i/o i (pb5) multiplexed pin whose function is selected by the int5 bit of the portbcfg register. if int5=0, the pin is the bi-directional i/o port bit pb5. if int5=1, the pin is the int5# interrupt register signal. the int5# pin is edge-sensitive, active low. 54 30 n/a 32 n/a pb6 or int6 i/o i (pb6) multiplexed pin whose function is selected by the int6 bit of the portbcfg register. if int6=0, the pin is the bi-directional i/o port bit pb6. if int6=1, the pin is the int6 interrupt request signal. the int6 pin is edge-sensitive, active high. table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
ez-usb trm v1.9 chapter 1. introducing ez-usb page 1-27 55 31 n/a 33 n/a pb7 or t2out i/o i (pb7) multiplexed pin whose function is selected by the t2out bit of the portbcfg register. if t2out=0, the pin is the bi-directional i/o port bit pb7. if t2out=1, the pin is the active-high t2out signal from 8051 timer2. t2out is active (high) for one clock cycle when timer/counter 2 overflows. 30 14 14 16 16 pc0 or rxd0 i/o i (pc0) multiplexed pin whose function is selected by the rxd0 bit of the portccfg register. if rxd0=0, the pin is the bi-directional i/o port bit pc0. if rxd0=1, the pin is the active-high rxd0 from 8051 uart0, which provides data to the uart in all modes. 31 15 15 17 17 pc1 or txd0 i/o i (pc1) multiplexed pin whose function is selected by the txd0 bit of the portccfg register. if txd0=0, the pin is the bi-directional i/o port bit pc1. if txd0=1, the pin is the active-high txd0 signal for 8051 uart0, which provides the output clock in sync mode, and the output data in async mode. 32 16 16 18 18 pc2 or int0# i/o i (pc2) multiplexed pin whose function is selected by the int0 bit of the portccfg register. if int0=0, the pin is the bi-directional i/o port bit pc2. if int0=1, the pin is the active-low 8051 int0 interrupt input signal, which is either edge triggered (it0=1) or level triggered (it0=0). 33 17 17 19 19 pc3 or int1# i/o i (pc3) multiplexed pin whose function is selected by the int1 bit of the portccfg register. if int1=0, the pin is the bi-directional i/o port bit pc3. if int1=1, the pin is the active-low 8051 int1 interrupt input signal, which is either edge triggered (it1=1) or level triggered (it1=0). 38 18 18 20 20 pc4 or t0 i/o i (pc4) multiplexed pin whose function is selected by the t0 bit of the portccfg register. if t0=0, the pin is the bi-directional i/o port bit pc4. if t0=1, the pin is the active-high t0 signal for 8051 timer0, which pro- vides the input to timer0 when c/t0 is 1. when c/ t0 is 0, timer0 does not use this bit. 39 19 19 21 21 pc5 or t1 i/o i (pc5) multiplexed pin whose function is selected by the t1 bit of the portccfg register. if t1=0, the pin is the bi-directional i/o port bit pc5. if t1=1, the pin is the active-high t1 signal from 8051 timer1, which provides the input to timer1 when c/t1 is 1. when c/t0 is 0, timer1 does not use this bit. table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
page 1-28 chapter 1. introducing ez-usb ez-usb trm v1.9 40 20 20 22 22 pc6 or wr# i/o i (pc6) multiplexed pin whose function is selected by the wr bit of the portccfg register. if wr=0, the pin is the bi-directional i/o port bit pc6. if wr=1, the pin is the active-low write signal for external mem- ory. if the wr# signal is used, it should be externally pulled up to vcc to ensure that the write strobe is inactive at power-on. 41 21 21 23 23 pc7 or rd# i/o i (pc7) multiplexed pin whose function is selected by the rd bit of the portccfg register. if rd#=0, the pin is the bi-directional i/o port bit pc7. if rd#=1, the pin is the active-low read signal for external memory. if the rd# signal is used, it should be externally pulled up to vcc to ensure that the read strobe is inactive at power-on. 4 2 2 2 2 clk24 output 24-mhz clock , phase locked to the 12-mhz input clock. it operates at 12 mhz in 12-mhz mode (48-pin package). output is disabled by setting the outclken bit = 0 in the cpucs register. 66 37 37 40 40 wakeup# input n/a usb wakeup . if the 8051 is in suspend, a high to low edge on this pin starts up the oscillator and inter- rupts the 8051 to allow it to exit the suspend mode. holding wakeup# low inhibits the ez-usb chip from entering the suspend state. 65 36 36 39 39 scl od z i 2 cclock . pull up to vcc with a 2.2k-ohm resistor, even if no i 2 c device is connected. 64 35 35 38 38 sda od z i 2 c data . connect to vcc with a 2.2k-ohm resistor even if no i 2 c device is connected. 2, 22, 42, 62 11, 22, 33, 44 11, 22, 33, 44 12,24, 36, 48 12, 24, 36, 48 vcc n/a vcc . 3.3v power source. 3, 5, 6, 13, 14, 17, 23, 43, 56, 63, 72, 78 1, 3, 4, 5, 6, 12,23, 34, 38 1, 3, 4, 5, 6, 12, 23, 34, 38 1, 3, 4, 5, 6, 13,25, 37, 41 1, 3, 4, 5, 6, 13, 25, 37, 41 gnd n/a ground. note: on the 80-pin package, pins 5, 6, 13, 14, and 72 are test pins that must be grounded for normal operation. driving pin 72 high floats all func- tional pins for automated board test. the corresponding pins on the 44-pin package are pins 3, 4, 5, 6, and 38. driving pin 38 high floats all functional pins for automated board test. the corresponding pins on the 48-pin package are pins 3, 4, 5, 6, and 41. driving pin 41 high floats all functional pins for automated board testing. n/a n/a n/a 15 15 cpu12mhz n/a this input controls the speed of the 8051: -tiedhigh-12mhz - tied low - 24 mhz 67 n/a n/a n/a n/a nc n/a this pin must be left unconnected. table 1-3. ez-usb series 2100 pinouts by pin function 2131q 2121s 2122s 2131s 2125s 2126s 2135s 2136s 2122t 2126t name type default description
ez-usb trm v1.9 chapter 2. ez-usb cpu page 2-1 2 ez-usb cpu the ez-usb built-in microprocessor, an enhanced 8051 core, is fully described in appen- dices a-c. this chapter introduces the processor, its interface to the ez-usb core, and describes architectural differences from a standard 8051. the enhanced 8051 core uses the standard 8051 instruction set. instructions execute faster than with the standard 8051 due to two features: ? wasted bus cycles are eliminated. a bus cycle uses four clocks, as compared to 12 clocks with the standard 8051. ? the 8051 runs at 24 mhz. in addition to the speed improvement, the enhanced 8051 core also includes architectural enhancements: 1. a second data pointer. 2. a second uart. 3. a third, 16-bit timer (timer2). 4. a high-speed memory interface with a non-multiplexed 16-bit address bus. 5. eight additional interrupts (int2-int5, pfi, t2, and uart1). 6. variable movx timing to accommodate fast/slow ram peripherals. 7. 3.3v operation. 2.1 introduction 2.2 8051 enhancements
page 2-2 chapter 2. ez-usb cpu ez-usb trm v1.9 the ez-usb chip provides additional enhancements outside the 8051. these include: ? fast external transfers (autopointer, fast transfer mode) ? vectored usb interrupts (autovector) ? separate buffers for setup and data portions of a control transfer. ? breakpoint facility. the 8051 communicates with the ez-usb core through a set of memory mapped regis- ters. these registers are grouped as follows: ? endpoint buffers and fifos ? 8051 control ? io ports ? fast transfer ?i 2 c controller ? interrupts ? usb functions these registers and their functions are described throughout this manual. a full descrip- tion of every register and bit appears in chapter 12, ez-usb registers. 2.3 ez-usb enhancements 2.4 ez-usb register interface
ez-usb trm v1.9 chapter 2. ez-usb cpu page 2-3 figure 2-1. 8051 registers like the standard 8051, the ez-usb 8051 core contains 128 bytes of register ram at 00- 7f, and a partially populated sfr register space at 80-ff. an additional 128 indirectly addressed registers (sometimes called idata) are also available at 80-ff. all internal ez-usb ram, which includes program/data memory, bulk endpoint buffer memory, and the ez-usb register set, is addressed as add-on 8051 memory. the 8051 reads or writes these bytes as data using the movx (move external) instruction. even though the movx instruction implies external memory, the ez-usb ram and register set is actually inside the ez-usb chip. external memory attached to the an2131q address and data busses can also be accessed by the movx instruction. the ez-usb core encodes its memory strobe and select signals (rd#, wr#, cs#, and oe#) to elimi- nate the need for external logic to separate the internal and external memory spaces. a standard 8051 communicates with its io ports 0-3 through four special function regis- ters (sfrs). standard 8051 io pins are quasi-bidirectional with weak pullups that briefly drive high only when the pin makes a zero-to-one transition. the ez-usb core implements io ports differently than a standard 8051 , as described in chapter 4, "ez-usb input/output." instead of using the 8051 io ports and sfrs, the ez-usb core implements a flexible io system that is controlled via ez-usb register set. each ez-usb io pin functions identically, having the following resources: ? an output latch. used when the pin is an output port. ? a bit that indicates the state of the io pin, regardless of its configuration (input or output). 2.5 ez-usb internal ram 2.6 i/o ports lower 128 bytes direct addr sfr space direct addr upper 128 bytes indirect addr 00 7f 80 ff
page 2-4 chapter 2. ez-usb cpu ez-usb trm v1.9 ? an output enable bit that causes the io pin to be driven from the output latch. ? an alternate function bit that determines whether the pin is general io or a special 8051 or ez-usb function. the sfrs associated with 8051 ports 0-3 are not implemented in ez-usb. these sfr addresses include p0 (0x80), p1 (0x90), p2 (0xa0), and p3 (0xb0). because p2 is not implemented, the movx@r0/r1 instruction takes the upper address byte from an added special function register (sfr) at location 0x92. this register is called mpage in the appendices. all standard 8051 interrupts are supported in the enhanced 8051 core. table 2-1 shows the existing and added 8051 interrupts, and indicates how the added ones are used. the ez-usb chip uses 8051 int2 for 21 different usb interrupts: 16 bulk endpoints plus sof, suspend, setup data, setup token, and usb bus reset. to help the 8051 deter- mine which interrupt is active, the ez-usb core provides a feature called autovectoring. the core inserts an address byte into the low byte of the 3-byte jump instruction found at the 8051 int2 vector address. this second level of vectoring automatically transfers con- trol to the appropriate usb isr. the autovector mechanism, as well as the ez-usb interrupt system is the subject of chapter 9, "ez-usb interrupts." 2.7 interrupts table 2-1. ez-usb interrupts standard 8051 interrupts enhanced 8051 interrupts used as int0 device pin int0# int1 device pin int1# timer 0 internal, timer 0 timer 1 internal, timer 1 tx0 & rx0 internal, uart0 int2 internal, usb int3 internal, i 2 c controller int4 device pin, pb4/int4 int5 device pin, pb5/int5# int6 device pin, pb6/int6 pf1 device pin, usb wakeup# tx1 & rx1 internal, uart1 timer 2 internal, timer 2
ez-usb trm v1.9 chapter 2. ez-usb cpu page 2-5 the ez-usb core implements a power-down mode that allows it to be used in usb bus powered devices that must draw no more than 500 m a when suspended. power control is accomplished using a combination of 8051 and ez-usb core resources. the mechanism by which ez-usb powers down for suspend, and then re-powers to resume operation, is described in detail in chapter 11, ez-usb power management. a suspend operation uses three 8051 resources, the idle mode and two interrupts. many enhanced 8051 architectures provide power control similar (or identical) to the ez-usb enhanced 8051 core. a usb suspend operation is indicated by a lack of bus activity for 3 ms. the ez-usb core detects this, and asserts an interrupt request via the usb interrupt (8051 int2). the isr (interrupt service routine) turns off external sub-systems that draw power. when ready to suspend operation, the 8051 sets an sfr bit, pcon.0. this bit causes the 8051 to suspend, waiting for an interrupt. when the 8051 sets pcon.0, a control signal from the 8051 to the ez-usb core causes the core to shut down the 12-mhz oscillator and internal pll. this stops all internal clocks to allow the ez-usb core and 8051 to enter a very low power mode. the suspended ez-usb chip can be awakened two ways: usb bus activity may resume, or an ez-usb pin (wakeup#) can be asserted to activate a usb remote wakeup . either event triggers the following chain of events: ? the ez-usb core re-starts the 12-mhz oscillator and pll, and waits for the clocks to stabilize ? the ez-usb core asserts a special, high-priority 8051 interrupt to signal a resume interrupt. ? the 8051 vectors to the resume isr, and upon completion resumes executing code at the instruction following the instruction that set the pcon.0 bit to 1. 2.8 power control
page 2-6 chapter 2. ez-usb cpu ez-usb trm v1.9 the ez-usb family was designed to keep 8051 coding as standard as possible, to allow easy integration of existing 8051 software development tools. the added 8051 sfr regis- ters and bits are summarized in table 2-2. 2.9 sfrs table 2-2. added registers and bits 8051 enhancements sfr addr function dual data pointers dpl0 0x82 data pointer 0 low addr dph0 0x83 data pointer 0 high addr dpl1 0x84 data pointer 1 low addr dph1 0x85 data pointer 1 high addr dps 0x86 data pointer select (lsb) mpage 0x92 replaces standard 8051 port 2 for indirect external data memory addressing timer 2 t2con.6-7 0xc8 timer 2 control rcap2l 0xca t2 capture/reload value l rcap2h 0xcb t2 capture/reload value h t2l 0xcc t2 count l t2h 0xcd t2 count h ie.5 0xa8 et2-enable t2 interrupt bit ip.5 0xb8 pt2-t2 interrupt priority control uart1 scon1.0-1 0xc0 serial port 1 control sbuf1 0xc1 serial port 1 data ie.6 0xa8 es1-sio1 interrupt enable bit ip.6 0xb8 ps1-sio1 interrupt priority control eicon.7 0xd8 smod1-sio1 baud rate doubler interrupts int2-int5 exif 0x91 int2-int5 interrupt flags eie 0xe8 int2-int5 interrupt enables eip.0-3 0xf8 int2-int5 interrupt priority control int6 eicon.3 0xd8 int6 interrupt flag eie.4 0xe8 int6 interrupt enable eip.4 0xf8 int6 interrupt priority control wakeup# eicon.4 0xd8 wakeup# interrupt flag eicon.5 0xd8 wakeup# interrupt enable idle mode pcon.0 0x87 ez-usb power down (suspend)
ez-usb trm v1.9 chapter 2. ez-usb cpu page 2-7 members of the ez-usb family that provide pins to expand 8051 memory provide sepa- rate non-multiplexed 16-bit address and 8-bit data busses. this differs from the standard 8051, which multiplexes eight device pins between three sources: io port 0, the external data bus, and the low byte of the address bus. a standard 8051 system with external mem- ory requires a de-multiplexing address latch, strobed by the 8051 ale (address latch enable) pin. the external latch is not required by the non-multiplexed ez-usb chip, and no ale signal is needed. in addition to eliminating the customary external latch, the non- multiplexed bus saves one cycle per memory fetch cycle, further improving 8051 perfor- mance. a standard 8051 user must choose between using port 0 as a memory expansion port or an io port. the an2131q provides a separate io system with its own control registers (in external memory space), and provides the io port signals on dedicated (not shared) pins. this allows the external data bus to be used to expand memory without sacrificing io pins. the 8051 is the sole master of the memory expansion bus. it provides read and write sig- nals to external memory. the address bus is output-only. a special fast transfer mode gives the ez-usb family the capability to transfer data to and from external memory over the expansion bus using a single movx instruction, which takes only two cycles (eight clocks) per byte. the internal 8051 reset signal is not directly controlled by the ez-usb reset pin. instead, it is controlled by an ez-usb register bit accessible to the usb host. when the ez-usb chip is powered, the 8051 is held in reset. using the default usb device (enu- merated by the usb core), the host downloads code into ram. finally, the host clears an ez-usb register bit that takes the 8051 out of reset. the ez-usb family also operates with external non-volatile memory, in which case the 8051 exits the reset state automatically at power-on. the various ez-usb resets and their effects are described in chapter 10, "ez-usb resets." 2.10 internal bus 2.11 reset
page 2-8 chapter 2. ez-usb cpu ez-usb trm v1.9
ez-usb trm v1.9 chapter 3. ez-usb memory page 3-1 3 ez-usb memory ez-usb devices divide ram into two regions, one for code and data, and the other for usb buffers and control registers. figure 3-1. ez-usb 8-kb memory map - addresses are in hexadecimal figure 3-2. ez-usb 4-kb memory map - addresses are in hexadecimal 3.1 introduction 1b40/7b40 data (rd/wr) ram code(psen) ram if ea=0 (6,976 bytes) registers/bulk buffers 7fff 7b40 0000 16 x 64-byte bulk endpoint buffers (1,024 bytes) usb control registers (192 bytes) 1f40/7f40 1fff/7fff 1f3f/7f3f 1b3f data (rd/wr) ram if isodisab=1 2000 27ff registers/bulk buffers 1fff 1b40 7c00 code(psen) and data (rd/wr) ram (4096 bytes) registers/bulk buffers 7fff 7b40 0000 13 x 64-byte bulk endpoint buffers (832 bytes) usb control registers (192 bytes) 7f40 7fff 7f3f 0fff
page 3-2 chapter 3. ez-usb memory ez-usb trm v1.9 figure 3-1 illustrates the two internal ez-usb ram regions. 6,976 bytes of general-pur- pose ram occupy addresses 0x0000-0x1b3f. this ram is loadable by the ez-usb core or i 2 c bus eeprom, and contains 8051 code and data. the ez-usb ea (external access) pin controls where the bottom segment of code (psen) memory is locatedinside (ea=0) or outside (ea=1) the ez-usb chip. if the ez pin is tied low, the ez-usb core internally ors the two 8051 read signals psen and rd for this region, so that code and data share the 0x0000-0x1b3f memory space. if ea=1, all code (psen) memory is external. 1,024 bytes of ram at 0x7b40-0x7f3f implement the sixteen bulk endpoint buffers. 192 additional bytes at 0x7f40-0x7fff contain the usb control registers. the 8051 reads and writes this memory using the movx instruction. in the 8-kb ram ez-usb version, the 1,024 bulk endpoint buffer bytes at 0x7b40-0x7f3f also appear at 0x1b40-0x1f3f. this aliasing allows unused bulk endpoint buffer memory to be added contiguously to the data memory, as illustrated figure 3-3. the memory space at 0x1f40-0x1fff should not be used. even though the 8051 can access ez-usb endpoint buffers at either 0x1b40 or 0x7b40, the firmware should be written to access this memory only at 0x7b40-0x7fff to maintain compatibility with future versions of ez-usb that contain more than 8 kb of ram. future versions will have the bulk buffer space at 0x7b40-0x7f3f only. 3.2 8051 memory about 8051 memory spaces the 8051 partitions its memory spaces into code memory and data memory. the 8051 reads code memory using the signal psen# (program store enable), reads data memory using the signal rd# (data read) and writes data memory using the signal wr# (data write). the 8051 movx (move external) instruction generates rd# or wr# strobes. psen# is a dedicated pin, while the rd# and wr# signals share pins with two io port signals: pc7/rd and pc6/wr. therefore, if expanded memory is used, the port pins pc7 and pc6 are not available to the system.
ez-usb trm v1.9 chapter 3. ez-usb memory page 3-3 figure 3-3. unused bulk endpoint buffers (shaded) used as data memory in the example shown in figure 3-3, only endpoints 0-in through 3-in are used for the usb function, so the data ram (shaded) can be extended to 0x1d7f. if an application uses none of the 16 ez-usb isochronous endpoints, the 8051 can set the isodisab bit in the isoctl register to disable all 16 isochronous endpoints, and make the 2-kb of isochronous fifo ram available as 8051 data ram at 0x2000-0x27ff. setting isodisab=1 is an all or nothing choice, as all 16 isochronous endpoints are dis- abled. an application that sets this bit must never attempt to transfer data over an isochro- nous endpoint. the memory map figures in the remainder of this chapter assume that isodisab=0, the default (and normal) case. ep0in ep0out ep1in ep1out ep2in ep2out ep3in ep3out ep4in ep4out ep5in ep5out ep6in ep06ut ep7in ep07out 1b40 code/data ram 0000 1b3f 1b80 1bc0 1c00 1c40 1c80 1cc0 1d00 1d40 1d80 1dc0 1e00 1e40 1e80 1ec0 1f00 1f40
page 3-4 chapter 3. ez-usb memory ez-usb trm v1.9 the 80-pin ez-usb package provides a 16-bit address bus, an 8-bit bus, and memory control signals psen#, rd#, and wr#. these signals are used to expand ez-usb memory. figure 3-4. ez-usb memory map with ea=0 figure 3-4 shows that when ea=0, the code/data memory is internal at 0x0000-0x1b40. external code memory can be added from 0x0000-0xffff, but it appears in the memory map only at 0x1b40-0xffff. addressing external code memory at 0x0000-0x1b3f when ea=0 causes the ez-usb core to inhibit the #psen strobe. this allows program memory to be added from 0x0000-0xffff without requiring decoding to disable it between 0x0000 and 0x1b3f. 3.3 expanding ez-usb memory code & data (psen,rd,wr) registers(rd,wr) external code memory (psen) external data memory (rd, wr) external data memory (rd,wr) 1b40 inside ez-usb outside ez-usb 8000 7b40 0000 1f3f ffff (note 2) note 1: ok to populate data memory here--rd#, wr#, cs# and oe# pins are inactive. (note 1) unused bulk buffers (rd,wr) note 2: ok to populate code memory here--no psen# strobe is generated. (note 1) 1fff 2000
ez-usb trm v1.9 chapter 3. ez-usb memory page 3-5 the internal block at 0x7b40-0x7fff (labeled registers) contains the bulk buffer mem- ory and ez-usb control registers. as previously mentioned, they are aliased at 0x1b40- 0x1fff to allow adding unused bulk buffer ram to general-purpose memory. 8051 code should access this memory only at the 0x7b40-0x7bff addresses. external ram may be added from 0x0000 to 0xffff, but the regions shown by note 1 in figure 3-4 are ignored; no external strobes or select signals are generated when the 8051 executes a movx instruction that addresses these regions. the ez-usb core automatically gates the standard 8051 rd# and wr# signals to exclude selection of external memory that exists internal to the ez-usb part. the psen# signal is also available on a pin for connection to external code memory. some 8051 systems implement external memory that is used as both data and program memory. these systems must logically or the psen# and rd# signals to qualify the chip enable and output enable signals of the external memory. to save this logic, the ez- usb core provides two additional control signals, cs# and oe#. the equations for these signals are as follows: ? cs# = rd# or wr# or psen# ? oe# = rd# or psen# because the rd#, wr#, and psen# signals are already qualified by the addresses allo- cated to external memory, these strobes are active only when external memory is accessed. 3.4 cs# and oe# signals
page 3-6 chapter 3. ez-usb memory ez-usb trm v1.9 figure 3-5. ez-usb memory map with ea=1 when ea=1 (figure 3-5), all code (psen) memory is external. all internal ez-usb ram is data memory. this gives the user over 6-kb of general-purpose ram, accessible by the movx instruction. note figures 3-4 and 3-5 assume that the ez-usb chip uses isochronous endpoints, and there- fore that the isodisab bit (isoctl.0) is lo. if isodisab=1, additional data ram appears internally at 0x2000-0x27ff, and the rd#, wr#, cs#, and oe# signals are modified to exclude this memory space from external data memory. data (rd,wr) registers(rd,wr) external code memory (psen) external data memory (rd, wr) external data memory (rd,wr) 1b40 inside ez-usb outside ez-usb 8000 7b40 0000 1f3f ffff note 1: ok to populate data memory here--rd#, wr#, cs# and oe# are inactive. (note 1) unused bulk buffers (rd,wr) (note 1) 1fff 2000
ez-usb trm v1.9 chapter 3. ez-usb memory page 3-7 the ez-usb 8-kb masked rom and 32-kb masked rom memory maps are shown in figures 3-6 and 3-7. figure 3-6. 8-kb rom, 2-kb ram version ez-usb rom versions contain program memory starting at 0x0000. in these versions, the internal ram is implemented as data-only memory. code for this rom version can be developed and tested using the an2131q with an external code memory (ea=1, figure 3-5). as long as the 8051 limits internal ram access to 0x0000-0x07ff and accesses the ez-usb registers and bulk data at 0x7b40- 0x7fff, the code in the external memory will be the identical image of the code that will ultimately be internal at 0x0000-0x1fff in the rom version. 3.5 ez-usb rom versions data (rd,wr) registers(rd,wr) external code memory (psen) external data memory (rd, wr) external data memory (rd,wr) 07ff inside ez-usb outside ez-usb 8000 7b40 0000 2000 ffff note 1: ok to populate data memory here, but no rd# or wr# strobes are generated. (note 1) (note 1) internal code memory(psen) (note 2) note 2: ok to populate code memory here, but no psen# strobe is generated. 0800
page 3-8 chapter 3. ez-usb memory ez-usb trm v1.9 figure 3-7. 32-kb rom, 4-kb ram version the ez-usb 32-kb rom version contains program memory from 0x0000 through 0x7fff, and data memory from 0x0000 through 0x0fff. code for this rom version can be developed and tested using the an2131q with an external code memory (ea=1, figure 3-5). as long as the 8051 limits internal ram access to 0x0000-0x0fff and accesses the ez-usb registers and bulk data at 0x7b40- 0x7fff, the code in the external memory will be the identical image of the code that will ultimately be internal at 0x0000-0x7fff in the rom version. data (rd,wr) registers(rd,wr) external code memory (psen) external data memory (rd, wr) external data memory (rd,wr) 0fff inside ez-usb outside ez-usb 8000 7b40 0000 1000 ffff note 1: ok to populate data memory here, but no rd# or wr# strobes are generated. (note 1) (note 1) internal code memory(psen) (note 2) note 2: ok to populate code memory here, but no psen# strobe is generated. 7fff
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-1 4 ez-usb input/output the ez-usb chip provides two input-output systems: ? a set of programmable io pins ? a programmable i 2 c controller this chapter begins with a description of the programmable io pins, and shows how they are shared by a variety of 8051 and ez-usb alternate functions such as uart, timer and interrupt signals. the i 2 c controller uses the scl and sda pins, and performs two functions: ? general-purpose 8051 use ? boot loading from an eeprom this chapter describes both the programming information for the 8051 i 2 c interface, and the operating details of the i 2 c boot loader. the role of the boot loader is described in chapter 5, "ez-usb enumeration and renumeration ? ." 4.1 introduction note 2.2-kb to 4.7-kb pullups are required on the sda and scl lines.
page 4-2 chapter 4. ez-usb cpu ez-usb trm v1.9 figure 4-1. ez-usb input/output pin the ez-usb family implements its io ports using memory-mapped registers. this is in contrast to a standard, which uses sfr bits for input/output. figure 4-1 shows the basic structure of an ez-usb io pin. twenty-four io pins are grouped into three 8-bit ports named porta, portb, and portc. the an2131q has all three ports, while the an2131s has portb, portc, and two porta bits. the 8051 accesses io pins using the three control bits shown in figure 4-1: oe, out, and pins. the out bit writes output data to a register, the oe bit turns on the output buffer, and the pins bit indicates the state of the pin. to configure a pin as an input, the 8051 sets oe=0 to turn off the output buffer. to config- ure a pin as an output, the 8051 sets oe=1 to turn on the output buffer, and writes data to the out register. the pins bit reflects the actual pin value regardless of the value of oe. a fourth control bit (in portacfg, portbcfg, portccfg registers) determines whether a port pin is general-purpose input/output (gpio) as shown in figure 4-1, or connected to an alternate 8051 or ez-usb function. table 4-1 lists the alternate functions available on the io pins. figure 4-1 shows the registers and bits associated with the io ports. 4.2 io ports reg out pin pins oe
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-3 depending on whether the alternate function is an input or output, the io logic is slightly different, as shown in figure 4-2 (output) and figure 4-3 (input). the last column of table 4-1 indicates which figure applies to each pin. table 4-1. io pin functions for portxcfg=0 and portxcfg=1 portxcfg bit = 0 portxcfg bit = 1 signal signal direction description figure pa0 t0out out timer 0 overflow pulse 4-2 pa1 t1out out timer 1 overflow pulse 4-2 pa2 oe# out ez-usb output enable 4-2 pa3 cs# out ez-usb chip select 4-2 pa4 fwr# out ez-usb fast write strobe 4-2 pa5 frd# out ez-usb fast read strobe 4-2 pa6 rxd0out out uart0 mode 0 data out 4-2 pa7 rxd1out out uart1 mode 0 data out 4-2 pb0 t2 in timer 2 clock input 4-3 pb1 t2ex in timer 2 capture/reload 4-3 pb2 rxd1 in uart1 receive data 4-3 pb3 txd1 out uart1 transmit data 4-2 pb4 int4 in interrupt 4 4-3 pb5 int5 in interrupt 5 4-3 pb6 int6 in interrupt 6 4-3 pb7 t2out out timer 2 overflow pulse 4-2 pc0 rxd0 in uart0 receive data 4-3 pc1 txd0 out uart0 transmit data 4-2 pc2 int0# in interrupt 0 4-3 pc3 int1# in interrupt 1 4-3 pc4 t0 in timer 0 clock input 4-3 pc5 t1 in timer 1 clock input 4-3 pc6 wr# out write strobe 4-2 pc7 rd# out read strobe 4-2
page 4-4 chapter 4. ez-usb cpu ez-usb trm v1.9 figure 4-2. alternate function is an output referring to figure 4-2, when portcfg=0, the io port is selected. in this case the alter- nate function (shaded) is disconnected and the pin functions exactly as shown in figure 4-1. when portcfg=1, the alternate function is connected to the io pin and the output register and buffer are disconnected. note that the 8051 can still read the state of the pin, and thus the alternate function value. figure 4-3. alternate function is an input referring to figure 4-3, when portcfg=0, the io port is selected. this is the general io port shown in figure 4-1 with one important differencethe alternate function is always listening . whether the port pin is set for output or input, the pin signal also drives the alternate function. 8051 firmware should ensure that if the alternate function is not used (if the pin is gpio only), the alternate input function is disabled. for example, suppose the pb4/int4 pin is configured for pb4. the pin signal is also routed to int4. if int4 is not used by the application, it should not be enabled. alterna- tively, enabling int4 could be useful, allowing io bit pb4 to trigger an interrupt. when portxcfg=1, the alternate function is selected. the output register and buffer are disconnected. the pins bit can still read the pin, and thus the input to the alternate func- tion. reg out pin pins oe alternate function output out pins alternate function output oe reg pin portcfg=0 ( port ) portcfg=1 ( alternate function ) reg out pin pins oe alternate function input out pins alternate function input oe reg pin portcfg=0 (port) portcfg=1 (alternate function)
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-5 figure 4-4. registers associated with ports a, b, and c figure 4-4 shows the registers associated with the ez-usb io ports. the power-on default for the portcfg bits is 0, selecting the io port function. the power-on default for the oe bits is 0, selecting the input direction. 4.3 io port registers rxd1out rxd0out frd fwr cs oe t1out t0out portacfg d7 d6 d5 d4 d3 d2 d1 d0 outa pinsa oea t2out int6 int5 int4 txd1 rxd1 t2ex t2 portbcfg outb pinsb oeb rd wr t1 t0 int1 int0 txd0 rxd0 portccfg outc pinsc oec d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0 d7 d6 d5 d4 d3 d2 d1 d0
page 4-6 chapter 4. ez-usb cpu ez-usb trm v1.9 4.4 i 2 c controller the usb core contains an i 2 c controller for boot loading and general-purpose i 2 c bus interface. this controller uses the scl (serial clock) and sda (serial data) pins. i2c controller describes how the boot load operates at power-on to read the contents of an external serial eeprom to determine the initial ez-usb fx configuration. the boot loader operates automatically, while the 8051 is held in reset. the last section of this chap- ter describes the operating details of the boot loader. after the boot sequence completes and the 8051 is brought out of reset, the general-pur- pose i 2 c controller is available to the 8051 for interface to external i 2 c devices, such as other eeproms, i/o chips, audio/video control chips, etc. 4.5 8051 i 2 c controller figure 4-5. general i 2 ctransfer figure 4-5 illustrates the waveforms for an i 2 c transfer. scl and sda are open-drain ez- usb pins, which must be pulled up to vcc with external resistors. the ez-usb chip is an i 2 c bus master only, meaning that it synchronizes data transfers by generating clock pulses on scl by driving low. once the master drives scl low, external slave devices can also drive scl low to extend clock cycle times. to synchronize i 2 c data, serial data (sda) is permitted to change state only while scl is low, and must be valid while scl is high. two exceptions to this rule are used to generate start and stop conditions. a start condition is defined as sda going low, while scl is high, and a stop condition is defined as sda going high, while scl is high. data is sent msb first. during the last bit time (clock #9 in figure 4-5), the master (ez-usb) floats the sda line to allow the slave to acknowledge the transfer by pulling sda low. 123456 7 8 9 d7 ack d6 d5 d4 d3 d2 d1 d0 start stop sda scl
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-7 figure 4-6. addressing an i 2 cperipheral thefirstbyteofani 2 c bus transaction contains the address of the desired peripheral. figure 4-7 shows the format for this first byte, which is sometimes called a control byte. a master sends the bit sequence shown in figure 4-6 after sending a start condition. the master uses this 9-bit sequence to select an i 2 c peripheral at a particular address, to establish the transfer direction (using r/w#), and to determine if the peripheral is present by testing for ack#. the four most significant bits sa3-sa0 are the peripheral chips slave address. i 2 c devices are pre-assigned slave addresses by device type, for example slave address 1010 is assigned to eeproms. the three bits da2-da0 usually reflect the states of i 2 cdevice address pins. devices with three address pins can be strapped to allow eight distinct addresses for the same device type. the eighth bit (r/w#) sets the direction for the ensu- ing data transfer, 1 for master read, and 0 for master write. most address transfers are fol- lowed by one or more data transfers, with the stop condition generated after the last data byte is transferred. in figure 4-6, a read transfer follows the address byte (at clock 8, the master sets the r/ w# bit high, indicating read). at clock 9, the peripheral device responds to its address by asserting ack. at clock 10, the master floats sda and issues scl pulses to clock in sda data supplied by this slave. assuming the 12-mhz crystal used by the ez-usb family, the scl frequency is 90.9 khz, giving an i 2 c transfer rate of 11 ms per bit. multiple i 2 cbusmasters the ez-usb chip acts only as an i 2 c bus master, never a slave. however, the 8051 can detect a second master by checking for berr=1 (section 4.7, "status bits"). 123456 7 8 9 sa3 ack sa2 sa1 sa0 da2 da1 da0 start sda d7 d6 10 11 r/w scl
page 4-8 chapter 4. ez-usb cpu ez-usb trm v1.9 figure 4-7. fc registers the 8051 uses the two registers shown in figure 4-7 to conduct i 2 c transfers. the 8051 transfers data to and from the i 2 c bus by writing and reading the i2dat register. the 12cs register controls i 2 c transfers and reports various status conditions. the three con- trol bits are start, stop, and lastrd. the remaining bits are status bits. writing to a status bit has no effect. 4.6.1 start the 8051 sets the start bit to 1 to prepare an i 2 c bus transfer. if start=1, the next 8051 load to i2dat will generate the start condition followed by the serialized byte of data in i2dat. the 8051 loads data in the format shown in figure 4-5 after setting the start bit. the i 2 c controller clears the start bit during the ack interval (clock 9 in figure 4-5). 4.6.2 stop the 8051 sets stop=1 to terminate an i 2 c bus transfer. the i 2 c controller clears the stop bit after completing the stop condition. if the 8051 sets the stop bit during a byte transfer, the stop condition will be generated immediately following the ack phase of the byte transfer. if no byte transfer is occurring when the stop bit is set, the stop condition will be carried out immediately on the bus. data should not be written to i2cs i2cs i 2 c control and status 7fa5 b7 b6 b5 b4 b3 b2 b1 b0 start stop lastrd id1 id0 berr ack done i2dat i 2 c data 7fa6 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 4.6 control bits
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-9 or i2dat until the stop bit returns low. in the 2122/2126 only, an interrupt request is available to signal that stop bit transmission is complete. 4.6.3 lastrd to read data over the i 2 c bus, an i 2 c master floats the sda line and issues clock pulses on the scl line. after every eight bits, the master drives sda low for one clock to indicate ack. to signal the last byte of the read transfer, the master floats sda at ack time to instruct the slave to stop sending. this is controlled by the 8051 by setting lastrd=1 before reading the last byte of a read transfer. the i 2 c controller clears the lastrd bit at the end of the transfer (at ack time). after a byte transfer the ez-usb controller updates the three status bits berr, ack, and done. if no stop condition was transmitted, they are updated at ack time. if a stop condition was transmitted they are updated after the stop condition is transmitted. 4.7.1 done the i 2 c controller sets this bit whenever it completes a byte transfer, right after the ack stage. the controller also generates an i 2 c interrupt request (8051 int3) when it sets the done bit. the i 2 c controller clears the done bit when the 8051 reads or writes the i2dat register, and the i 2 c interrupt request bit whenever the 8051 reads or writes the i2cs or i2dat register. 4.7.2 ack every ninth scl of a write transfer, the slave indicates reception of the byte by asserting ack. the ez-usb controller floats sda during this time, samples the sda line, and updates the ack bit with the complement of the detected value. ack=1 indicates acknowledge, and ack=0 indicates not-acknowledge. the ez-usb core updates the note setting lastrd does not automatically generate a stop condition. the 8051 should also set the stop bit at the end of a read transfer. 4.7 status bits
page 4-10 chapter 4. ez-usb cpu ez-usb trm v1.9 ack bit at the same time it sets done=1. the ack bit should be ignored for read trans- fers on the bus. 4.7.3 berr this bit indicates an i 2 c bus error. berr=1 indicates that there was bus contention, which results when an outside device drives the bus lo when it shouldnt, or when another bus master wins arbitration, taking control of the bus. berr is cleared when the 8051 reads or writes the i2dat register. 4.7.4 id1, id0 these bits are set by the boot loader (section 4.10, "i 2 c boot loader") to indicate whether an 8-bit address or 16-bit address eeprom at slave address 000 or 001 was detected at power-on. they are normally used only for debug purposes. table 4-3 shows the encod- ing for these bits. to send a multiple byte data record over the i 2 c bus, follow these steps: 1. set the start bit. 2. write the peripheral address and direction=0 (for write) to i2dat. 3. wait for done=1*. if berr=1 or ack=0, go to step 7. 4. load i2dat with a data byte. 5. wait for done=1*. if berr=1 or ack=0 go to step 7. 6. repeat steps 4 and 5 for each byte until all bytes have been transferred. 7. set stop=1. * if the i 2 c interrupt (8051 int3) is enabled, each wait for done=1 step can be inter- rupt driven, and handled by an interrupt service routine. see section 9.12, "i 2 c inter- rupt for more details regarding the i 2 c interrupt. 4.8 sending i 2 c data
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-11 to read a multiple-byte data record, follow these steps: 1. set the start bit. 2. write the peripheral address and direction=1 (for read) to i2dat. 3. wait for done=1*. if berr=1 or ack=0, terminate by setting stop=1. 4. read i2dat and discard the data. this initiates the first burst of nine scl pulses to clock in the first byte from the slave. 5. wait for done=1*. if berr=1, terminate by setting stop=1. 6. read the data from i2dat. this initiates another read transfer. 7. repeat steps 5 and 6 for each byte until ready to read the second-to-last byte. 8. before reading the second-to-last i2dat byte, set lastrd=1. 9. read the data from i2dat. with lastrd=1, this initiates the final byte read on the i 2 c bus. 10. wait for done=1*. if berr=1, terminate by setting stop=1. 11. set stop=1. 12. read the last byte from i2dat immediately (the next instruction) after setting the stop bit. this retrieves the last data byte without initiating an extra read transac- tion (nine more scl pulses) on the i 2 c bus. * if the i 2 c interrupt (8051 int3) is enabled, each wait for done=1 step can be inter- rupt-driven, and handled by an interrupt service routing. see section 9.12, "i 2 c inter- rupt for more details regarding the i 2 c interrupt. 4.9 receiving i 2 c data
page 4-12 chapter 4. ez-usb cpu ez-usb trm v1.9 when the ez-usb chip comes out of reset, the ez-usb boot loader checks for the pres- ence of an eeprom on its i 2 c bus. if an eeprom is detected, the loader reads the first eeprom byte to determine how to enumerate (specifically, whether to supply id infor- mation from the ez-usb core or from the eeprom). the various enumeration modes are described in chapter 5, "ez-usb enumeration and renumeration ? ." prior to reading the first eeprom byte, the boot loader must set an address counter inside the eeprom to zero. it does this by sending a control byte (write) to select the eeprom, followed by a zero address to set the internal eeprom address pointer to zero. then it issues a control byte (read), and reads the first eeprom byte. the ez-usb boot loader supports two i 2 c eeprom types: ? eeproms with address a[7..4]=1010 that use an 8-bit address (example: 24lc00, lc01/a, lc02/a). ? eeproms with address a[7..4]=1010 that use a 16-bit address (example: 24lc00, lc01/a, lc02/a). eeproms with densities up to 256 bytes require loading a single address byte. larger eeproms require loading two address bytes. the ez-usb i 2 c controller needs to determine which eeprom type is connectedone or two address bytesso that it can properly reset the eeprom address pointer to zero before reading the eeprom. for the single-byte address part, it must send a single zero byte of address, and for the two-byte address part it must send two zero bytes of address. because there is no direct way to detect which eeprom typesingle or double addressis connected, the i 2 c controller uses the eeprom address pins a2, a1, and a0 to determine whether to send out one or two bytes of address. this algorithm requires that the eeprom address lines are strapped as shown in table 4-2. single-byte-address eeproms are strapped to address 000 and double-byte-address eeproms are strapped to address 001. 4.10 i 2 c boot loader
ez-usb trm v1.9 chapter 4. ez-usb cpu page 4-13 * this eeprom does not have address pins the i 2 c controller performs a three-step test at power-on to determine whether a one-byte- address or a two-byte-address eeprom is attached. this test proceeds as follows: 1. the i 2 c controller sends out a read current address command to i 2 c sub-address 000 (10100001). if no ack is returned, the controller proceeds to step 2. if ack is returned, the one-byte-address device is indicated. the controller discards the data and proceeds to step 3. 2. the i 2 c controller sends out a read current address command to i 2 c sub-address 001 (10100011). if ack is returned, the two-byte-address device is indicated. the controller discards the data and proceeds to step 3. if no ack is returned, the controller assumes that a valid eeprom is not connected, assumes the no serial eeprom mode, and terminates the boot load. 3. the i 2 c controller resets the eeprom address pointer to zero (using the appropri- ate number of address bytes), then reads the first eeprom byte. if it does not read 0xb0 or 0xb2, the controller assumes the no serial eeprom mode. if it reads either 0xb0 or 0xb2, the controller copies the next six bytes into internal storage, and if it reads 0xb2, it proceeds to load the eeprom contents into inter- nal ram. table 4-2. strap boot eeprom address lines to these values bytes example eeprom a2 a1 a0 16 24lc00* n/a n/a n/a 128 24lc01 0 0 0 256 24lc02 0 0 0 4k 24lc32 0 0 1 8k 24lc64 0 0 1
page 4-14 chapter 4. ez-usb cpu ez-usb trm v1.9 the results of this power-on test are reported in the id1 and id0 bits, as shown in table 4-3. other eeprom devices (with device address of 1010) can be attached to the i 2 c bus for general purpose 8051 use, as long as they are strapped for address other than 000 or 001. if a 24lc00 eeprom is used, no other eeproms with device address 1010 may be used, because the 24lc00 responds to all eight sub-addresses. table 4-3. results of power-on i 2 ctest id1 id0 meaning 0 0 no eeprom detected 0 1 one-byte-address load eeprom detected 1 0 two-byte-address load eeprom detected 1 1 not used
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-1 5 ez-usb enumeration and renumeration ? the ez-usb chip is soft . 8051 code and data is stored in internal ram, which is loaded from the host using the usb interface. peripheral devices that use the ez-usb chip can operate without rom, eprom, or flash memory, shortening production lead times and making firmware updates a breeze. to support the soft feature, the ez-usb chip automatically enumerates as a usb device without firmware , so the usb interface itself may be used to download 8051 code and descriptor tables. the ez-usb core performs this initial (power-on) enumeration and code download while the 8051 is held in reset. this initial usb device, which supports code download, is called the default usb device. after the code descriptor tables have been downloaded from the host to ez-usb ram, the 8051 is brought out of reset and begins executing the device code. the ez-usb device enumerates again, this time as the loaded device. this second enumeration is called renumeration ? , which the ez-usb chip accomplishes by electrically simulat- ing a physical disconnection and re-connection to the usb. an ez-usb control bit called renum (renumerated) determines which entity, the core or the 8051, handles device requests over endpoint zero. at power-on, the renum bit (usbcs.1) is zero, indicating that the ez-usb core automatically handles device requests. once the 8051 is running, it can set renum=1 to indicate that user 8051 code handles subsequent device requests using its downloaded firmware. chapter 7, "ez-usb endpoint zero" describes how the 8051 handles device requests while renum=1. it is also possible for the 8051 to run with renum=0 and have the ez-usb core handle certain endpoint zero requests (see the text box, another use for the default usb device on page 5-2). this chapter deals with the various ez-usb startup modes, and describes the default usb device that is created at initial enumeration. 5.1 introduction
page 5-2 chapter 5. ez-usb cpu ez-usb trm v1.9 the default usb device consists of a single usb configuration containing one interface (interface 0) with three alternate settings 0, 1, and 2. the endpoints reported for this device are shown in table 5-1. note that alternate setting zero uses no interrupt or isoch- ronous bandwidth, as recommended by the usb specification. another use for the default usb device the default usb device is established at power-on to set up a usb device capable of downloading firmware into ez-usb ram. another useful feature of the ez-usb default device is that 8051 code can be written to support the already-configured generic usb device. before bringing the 8051 out of reset, the ez-usb core enables certain endpoints and reports them to the host via descriptors. by utilizing the usb default machine (by keeping renum=0), the 8051 can, with very little code, perform meaningful usb transfers that use these default endpoints. this accelerates the usb learning curve. to see an example of how little code is actually necessary, take a look at section 6.11, "polled bulk transfer example." 5.2 the default usb device table 5-1. ez-usb default endpoints endpoint type alternate setting 0 1 2 maximum packet size (bytes) 0 ctl 64 64 64 1-in int 0 16 64 2-in bulk 0 64 64 2-out bulk 0 64 64 4-in bulk 0 64 64 4-out bulk 0 64 64 6-in bulk 0 64 64 6-out bulk 0 64 64 8-in iso 0 16 256 8-out iso 0 16 256 9-in iso 0 16 16 9-out iso 0 16 16 10-in iso 0 16 16 10 out iso 0 16 16
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-3 for purposes of downloading 8051 code, the default usb device requires only con- trol endpoint zero. nevertheless, the usb default machine is enhanced to support other endpoints as shown in figure 5-1 (note the alternate settings 1 and 2). this enhance- ment is provided to allow the developer to get a head start generating usb traffic and learning the usb system. all the descriptors are automatically handled by the ez-usb core, so the developer can immediately start writing code to transfer data over usb using these pre-configured endpoints. when the ez-usb core establishes the default usb device, it also sets the proper end- point configuration bits to match the descriptor data supplied by the ez-usb core. for example, bulk endpoints 2, 4, and 6 are implemented in the default usb device, so the ez-usb core sets the corresponding epval bits. chapter 6, ez-bulk transfers con- tains a detailed explanation of the epval bits. tables 5-9 through 5-13 show the various descriptors returned to the host by the ez-usb core when renum=0. these tables describe the usb endpoints defined in table 5-1, along with other usb details, and should be useful to help understand the structure of usb descriptors.
page 5-4 chapter 5. ez-usb cpu ez-usb trm v1.9 table 5-2 shows how the ez-usb core responds to endpoint zero requests when renum=0. the usb host enumerates by issuing: ? set_address ? get_descriptor ? set_configuration (to 1) 5.3 ez-usb core response to ep0 device requests table 5-2. how the ez-usb core handles ep0 requests when renum=0 brequest name action: renum=0 0x00 get status/device returns two zero bytes 0x00 get status/endpoint supplies ep stall bit for indicated ep 0x00 get status/interface returns two zero bytes 0x01 clear feature/device none 0x01 clear feature/endpoint clears stall bit for indicated ep 0x02 (reserved) none 0x03 set feature/device none 0x03 set feature endpoint sets stall bit for indicated ep 0x04 (reserved) none 0x05 set address updates fnadd register 0x06 get descriptor supplies internal table 0x07 set descriptor none 0x08 get configuration returns internal value 0x09 set configuration sets internal value 0x0a get interface returns internal value (0-3) 0x0b set interface sets internal value (0-3) 0x0c sync frame none vendor requests 0x0a firmware load upload/download ram 0xa1-0xaf reserved reserved by cypress semiconductor all other none
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-5 as shown in table 5-2, after enumeration, the ez-usb core responds to the following host requests. ? set or clear an endpoint stall (set/clear feature-endpoint). ? read the stall status for an endpoint (get_status_endpoint). ? set/read an 8-bit configuration number (set/get_configuration). ? set/read a 2-bit interface alternate setting (set/get_interface). ? download or upload 8051 ram. to ensure proper operation of the default keil monitor, which uses sio-1 (rxd1 and txd1), never change the following port config bits from 1: ? portbcfg bits 2 (rxd1) and 3 (txd1). to ensure the 8051 processor can access the external sram (including the keil monitor), do not change the following bits from 1: ? portccfg bits 6 (wr#) and 7 (rd#). to ensure that no bits are unintentionally changed, all writes to the portxcfg registers should use a read-modify-write series of instructions. the usb specification provides for vendor-specific requests to be sent over control endpoint zero. the ez-usb chip uses this feature to transfer data between the host and ez-usb ram. the ez-usb core responds to two firmware load requests, as shown in tables 5-3 and 5-4. 5.4 firmware load table 5-3. firmware download byte field value meaning 8051 response 0 bmrequest 0x40 vendor request, out none required 1 brequest 0xa0 firmware load 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlenghtl lenl number of bytes 7 wlengthh lenh
page 5-6 chapter 5. ez-usb cpu ez-usb trm v1.9 these requests are always handled by the ez-usb core (renum=0 or 1). this means that 0xa0 is reserved by the ez-usb chip, and therefore should never be used for a vendor request. cypress semiconductor also reserves brequest values 0xa1 through 0xaf, so your system should not use these brequest values. a host loader program typically writes 0x01 to the cpucs register to put the 8051 into reset, loads all or part of the ez-usb ram with 8051 code, and finally reloads the cpucs register with 0 to take the 8051 out of reset. the cpucs register is the only usb register that can be written using the firmware download command. firmware loads are restricted to internal ez-usb memory. table 5-4. firmware upload byte field value meaning 8051 response 0 bmrequest 0xc0 vendor request, in none required 1 brequest 0xa0 firmware load 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl number of bytes 7 wlengthh lenh when renum=1 at power-on at power-on, the renum bit is normally set to zero so that the ez-usb handles device requests over control endpoint zero. this allows the core to download 8051 firm- ware and then reconnect as the target device. at power-on, the ez-usb core checks the i 2 c bus for the presence of an eeprom. if it finds one, and the first byte of the eeprom is 0xb2, the core copies the contents of the eeprom into internal ram, sets the renum bit to 1, and un-resets the 8051. the 8051 wakes up ready-to-run firmware in ram. the required data form at for this load module is described in the next section.
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-7 when the ez-usb chip comes out of reset, the ez-usb core makes a decision about how to enumerate based on the contents of an external eeprom on its i 2 c bus. table 5-5 shows the choices. in table 5-5, pid means product id, vid means version id, and did means device id. if no eeprom is present, or if one is present but the first byte is neither 0xb0 nor 0xb2, the ez-usb core enumerates using internally stored descriptor data, which contains the cypress semiconductor vid, pid, and did. these id bytes cause the host operating sys- tem to load a cypress semiconductor device driver. the ez-usb core also establishes the default usb device . this mode is only used for code development and debug. if a serial eeprom is attached to the i 2 c bus and its first byte is 0xb0, the ez-usb core enumerates with the same internally stored descriptor data as for the no-eeprom case, but with one difference. it supplies the pid/vid/did data from six bytes in the external eeprom rather than from the ez-usb core. the custom vid/pid/did in the eeprom causes the host operating system to load a device driver that is matched to the eeprom vid/pid/did. this ez-usb operating mode provides a soft usb device using renu- meration ?. if a serial eeprom is attached to the i 2 c bus and its first byte is 0xb2, the ez-usb core transfers the contents of the eeprom into internal ram. the ez-usb core also sets the renum bit to 1 to indicate that the 8051 (and not the ez-usb core) responds to device requests over control endpoint zero (see the text box, when renum=1 at power- on on page 5-6). therefore, all descriptor data, including vid/did/pid values, are sup- plied by the 8051 firmware. the last byte loaded from the eeprom (to the cpucs reg- ister) releases the 8051 reset signal, allowing the ez-usb chip to come up as a fully custom device with firmware in ram. the following sections discuss these enumeration methods in detail. 5.5 enumeration modes table 5-5. ez-usb core action at power-up first eeprom byte ez-usb core action not 0xb0 or 0xb2 supplies descriptors, pid/vid/did from ez-usb core. sets renum=0. 0xb0 supplies descriptors from ez-usb core, pid/vid/did from eeprom. sets renum=0. 0xb2 loads eeprom into ez-usb ram. sets renum=1; therefore 8051 supplies descriptors, pid/vid/did.
page 5-8 chapter 5. ez-usb cpu ez-usb trm v1.9 in the simplest case, no serial eeprom is present on the i 2 c bus, or an eeprom is present but its first byte is not 0xb0 or 0xb2. in this case, descriptor data is supplied by a table internal to the ez-usb core. the ez-usb chip comes on as the usb default device , with the id bytes shown in table 5-6. the usb host queries the device during enumeration, reads the device descriptor, and uses the table 5-6 bytes to determine which software driver to load into the operating system. this is a major usb featuredrivers are dynamically matched with devices and automat- ically loaded when a device is plugged in. the no_eeprom case is the simplest configuration, but also the most limiting. this mode is used only for code development, utilizing cypress software tools matched to the id values in table 5-6. the other half of the i 2 cstory the ez-usb i 2 c controller serves two purposes. first, as described in this chapter, it manages the serial eeprom interface that operates automatically at power-on to deter- mine the enumeration method. second, once the 8051 is up and running, the 8051 can access the i 2 c controller for general-purpose use. this makes a wide range of standard i 2 c peripherals available to an ez-usb system. other i 2 c devices can be attached to the scl and sda lines of the i 2 c bus as long as there is no address conflict with the serial eeprom described in this chapter. chapter 4, "ez-usb input/output" describes the general-purpose nature of the i 2 c interface. 5.6 no serial eeprom table 5-6. ez-usb device characteristics, no serial eeprom vendor id 0x0547 (cypress semiconductor) product id 0x2131 (ez-usb) device release 0xxxyy (depends on revision)
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-9 if, at power-on, the ez-usb core detects an eeprom connected to its i 2 c port with the value 0xb0 at address 0, the ez-usb core copies the vendor id (vid), product id (pid), and device id (did) from the eeprom (table 5-7) into internal storage. the ez-usb core then supplies these bytes to the host as part of the get_descriptor-device request. (these six bytes replace only the vid/pid/did bytes in the default usb device descrip- tor.) this causes a driver matched to the vid/pid/did values in the eeprom, instead of those in the ez-usb core, to be loaded into the os. after initial enumeration, the driver downloads 8051 code and usb descriptor data into ez-usb ram and starts the 8051. the code then renumerates ? to come on as the fully custom device. a recommended eeprom for this application is the microchip 24lc00, a small (5-pin sot package) inexpensive 16-byte serial eeprom. a 24lc01 (128 bytes) or 24lc02 (256 bytes) may be substituted for the 24lc00, but as with the 24lc00, only the first seven bytes are used. reminder the ez-usb core uses the table 5-6 data for enumeration only if the renum bit is zero. if renum=1, enumeration data is supplied by 8051 code. 5.7 serial eeprom present, first byte is 0xb0 table 5-7. eeprom data format for b0 load eeprom address contents 0 0xb0 1 vendor id (vid) l 2 vendor id (vid) h 3 product id (pid) l 4 product id (pid) h 5 device id (did) l 6 device id (did) h 7 not used
page 5-10 chapter 5. ez-usb cpu ez-usb trm v1.9 if, at power-on, the ez-usb core detects an eeprom connected to its i 2 c port with the value 0xb2 at address 0; the ez-usb core loads the eeprom data into ez-usb ram. it also sets the renum bit to 1, causing device requests to be fielded by the 8051 instead of the ez-usb core. the eeprom data format is shown in table 5-8. the first byte tells the ez-usb core to copy eeprom data into ram. the next six bytes (1-6) are ignored (see the text box, vid/pid/did in a b2 eeprom on page 5-11). 5.8 serial eeprom present, first byte is 0xb2 table 5-8. eeprom data format for b2 load eeprom address contents 0 0xb2 1 vendor id (vid) l 2 vendor id (vid) h 3 product id (pid) l 4 product id (pid) h 5 device id (did) l 6 device id (did) h 7 length h 8 length l 9 startaddr h 10 startaddr l --- data block --- --- length h --- length l --- startaddr h --- startaddr l --- data block --- --- 0x80 --- 0x01 --- 0x7f --- 0x92 --- last 00000000
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-11 one or more data records follow, starting at eeprom address 7. the maximum value of length h is 0x03, allowing a maximum of 1,023 bytes per record. each data record con- sists of a length, a starting address, and a block of data bytes. the last data record must have the msb of its length h byte set to 1. the last data record consists of a single-byte load to the cpucs register at 0x7f92. only the lsb of this byte is significant 8051res (cpucs.0) is set to zero to bring the 8051 out of reset. serial eeprom data can be loaded into two ez-usb ram spaces only. ? 8051 program/data ram at 0x0000-0x1b40. ? the cpucs register at 0x7f92 (only bit 0, 8051 reset, is host-loadable). three ez-usb control bits in the usbcs (usb control and status) register control the renumeration ? process: discon, discoe, and renum. figure 5-1. usb control and status register vid/pid/did in a b2 eeprom bytes 1-6 of a b2 eeprom can be loaded with vid/pid/did bytes if it is desired at some point to run the 8051 program with renum=0 (ez-usb core handles device requests), using the eeprom vid/pid/did rather than the cypress semiconductor val- ues built into the ez-usb core. 5.9 renumeration ? usbcs usb control and status 7fd6 b7 b6 b5 b4 b3 b2 b1 b0 wa k e s r c - - - discon discoe renum sigrsume r/w r r r r/w r/w r/w r/w 00000100
page 5-12 chapter 5. ez-usb cpu ez-usb trm v1.9 figure 5-2. disconnect pin logic the logic for the discon and discoe bits is shown in figure 5-2. to simulate a usb disconnect, the 8051 writes the value 00001010 to usbcs. this floats the discon# pin, and provides an internal discon signal to the usb core that causes it to perform discon- nect housekeeping. to re-connect to usb, the 8051 writes the value 00000110 to usbcs. this presents a logic hi to the discon# pin, enables the output buffer, and sets the renum bit hi to indicate that the 8051 (and not the usb core) is now in control for usb transfers. this arrangement allows connecting the 1,500-ohm resistor directly between the discon# pin and the usb d+ line (figure 5-3). figure 5-3. typical disconnect circuit (discoe=1) internal logic discon discoe discon# pin discon# d- d+ ez-usb to 3.3v regulator 1500 j1 usb-b vcc 1 d- 2 d+ 3 gnd 4
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-13 the 8051 can renumerate ? anytime. once use for this capability might be to fine tune an isochronous endpoints bandwidth requests by trying various descriptor values and renumerating. tables 5-9 through 5-19 show the descriptor data built into the ez-usb core. the tables are presented in the order that the bytes are stored. the device descriptor specifies a maxpacketsize of 64 bytes for endpoint 0, contains cypress semiconductor vendor, product and release number ids, and uses no string indices. release number ids ( xx and yy ) are found in individual cypress semiconductor data sheets. the ez-usb core returns this information response to a get_descriptor/ device host request. 5.10 multiple renumerations ? 5.11 default descriptor table 5-9. usb default device descriptor offset field description value 0 blength length of this descriptor = 18 bytes 12h 1 bdescriptortype descriptor type = device 01h 2 bcdusb (l) usb specification version 1.00 (l) 00h 3 bcdusb (h) usb specification version 1.00 (h) 01h 4 bdeviceclass device class (ff is vendor-specific) ffh 5 bdevicesubclass device sub-class (ff is vendor-specific) ffh 6 bdeviceprotocol device protocol (ff is vendor-specific) ffh 7 bmaxpacketsize0 maximum packet size for ep0 = 64 bytes 40h 8 idvendor (l) vendor id (l) cypress semiconductor = 0547h 47h 9 idvendor (h) vendor id (h) 05h 10 idproduct (l) product id (l) ez-usb = 2131h 31h 11 idproduct (h) product id (h) 21h 12 bcddevice (l) device release number (bcd,l) (see individual data sheet) 21h 13 bcddevice (h) device release number (bcd,h) (see individual data sheet) yyh 14 imanufacturer manufacturer index string = none 00h 15 iproduct product index string = none 00h 16 iserialnumber serial number index string = none 00h 17 bnumconfigurations number of configurations in this interface = 1 01h
page 5-14 chapter 5. ez-usb cpu ez-usb trm v1.9 the configuration descriptor includes a total length field (offset 2-3) that encompasses all interface and endpoint descriptors that follow the configuration descriptor. this configu- ration describes a single interface (offset 4). the host selects this configuration by issuing a set_configuration requests specifying configuration #1 (offset 5). interface 0, alternate setting 0 describes endpoint 0 only. this is a zero bandwidth setting. the interface has no string index. table 5-10. usb default configuration descriptor offset field description value 0 blength length of this descriptor = 9 bytes 09h 1 bdescriptortype descriptor type = configuration 02h 2 wtotallength (l) total length (l) including interface and endpoint descriptors dah 3 wtotallength (h) total length (h) 00h 4 bnuminterfaces number of interfaces in this configuration 01h 5 bconfigurationvalue configuration value used by set_configuration request to select this configuration 01h 6 iconfiguration index of string describing this configuration = none 00h 7 bmattributes attributes - bus-powered, no wakeup 80h 8 maxpower maximum power - 100 ma 32h table 5-11. usb default interface 0, alternate setting 0 descriptor offset field description value 0 blength length of the interface descriptor 09h 1 bdescriptortype descriptor type = interface 04h 2 binterfacenumber zero-based index of this interface = 0 00h 3 balternatesetting alternate setting value = 0 00h 4 bnumendpoints number of endpoints in this interface (not counting epo) = 0 00h 5 binterfaceclass interface class = vendor specific ffh 6 binterfacesubclass interface sub-class = vendor specific ffh 7 binterfaceprotocol interface protocol = vendor specific ffh 8 iinterface index to string descriptor for this interface = none 00h
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-15 interface 0, alternate setting 1 has thirteen endpoints, whose individual descriptors follow the interface descriptor. the alternate settings have no string indices. interface 0, alternate setting 1 has one interrupt endpoint, in1, which has a maximum packet size of 16 and a polling interval of 10 ms. table 5-12. usb default interface 0, alternate setting 1 descriptor offset field description value 0 blength length of the interface descriptor 09h 1 bdescriptortype descriptor type = interface 04h 2 binterfacenumber zero-based index of this interface = 0 00h 3 balternatesetting alternate setting value = 1 01h 4 bnumendpoints number of endpoints in this interface (not counting epo) = 13 0dh 5 binterfaceclass interface class = vendor specific ffh 6 binterfacesubclass interface sub-class = vendor specific ffh 7 binterfaceprotocol interface protocol = vendor specific ffh 8 iinterface index to string descriptor for this interface = none 00h table 5-13. usb default interface 0, alternate setting 1, interrupt endpoint descriptor offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in1 81h 3 bmattributes xfr type = int 03h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds = 10 ms 0ah
page 5-16 chapter 5. ez-usb cpu ez-usb trm v1.9 table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in2 82h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out2 02h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in4 84h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out4 04h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in6 86h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-17 interface 0, alternate setting 1 has six bulk endpoints with max packet sizes of 64 bytes. even numbered endpoints were chosen to allow endpoint pairing. for more on endpoint pairing, see chapter 6, "ez-usb bulk transfers." table 5-14. usb default interface 0, alternate setting 1, bulk endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out6 06h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h
page 5-18 chapter 5. ez-usb cpu ez-usb trm v1.9 table 5-15. usb default interface 0, alternate setting 1, isochronous endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in8 88h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out8 08h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in9 89h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out9 09h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in10 8ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out10 0ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-19 interface 0, alternate setting 1 has six isochronous endpoints with maximum packet sizes of 16 bytes. this is a low bandwidth setting. interface 0, alternate setting 2 has thirteen endpoints, whose individual descriptors follow the interface descriptor. alternate setting 2 differs from alternate setting 1 in the maxi- mum packet sizes of its interrupt endpoint and two of its isochronous endpoints (ep8in and ep8out). alternate setting 2 for the interrupt 1-in increases the maximum packet size for the inter- rupt endpoint to 64. table 5-16. usb default interface 0, alternate setting 2 descriptor offset field description value 0 blength length of the interface descriptor 09h 1 bdescriptor type descriptor type = interface 04h 2 binterfacenumber zero-based index of this interface = 0 00h 3 balternatesetting alternate setting value = 2 02h 4 bnumendpoints number of endpoints in this interface (not counting epo) = 13 0dh 5 binterfaceclass interface class = vendor specific ffh 6 binterfacesubclass interface sub-class = vendor specific ffh 7 binterfaceprotocol interface protocol = vendor specific ffh 8 iinterface index to string descriptor for this interface = none 00h table 5-17. usb default interface 0, alternate setting 1, interrupt endpoint descriptor offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in1 81h 3 bmattributes xfr type = int 03h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds = 10 ms 0ah
page 5-20 chapter 5. ez-usb cpu ez-usb trm v1.9 the bulk endpoints for alternate setting 2 are identical to alternate setting 1. table 5-18. usb default interface 0, alternate setting 2, bulk endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptor type descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in2 82h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out2 02h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in4 84h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out4 04h 3 bmattributes xfr type = iso 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in6 86h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out6 06h 3 bmattributes xfr type = bulk 02h 4 wmaxpacketsize (l) maximum packet size = 64 bytes 40h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 00h
ez-usb trm v1.9 chapter 5. ez-usb cpu page 5-21 the only differences between alternate settings 1 and 2 are the maximum packet sizes for ep8in and ep8out. this is a high-bandwidth setting using 256 bytes each. table 5-19. usb default interface 0, alternate setting 2, isochronous endpoint descriptors offset field description value 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in8 88h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 256 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 01h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out8 08h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 256 bytes 00h 5 wmaxpacketsize (h) maximum packet size - high 10h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in9 89h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out9 09h 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = in10 8ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h 0 blength length of this endpoint descriptor 07h 1 bdescriptortype descriptor type = endpoint 05h 2 bendpointaddress endpoint direction (1 is in) and address = out10 0ah 3 bmattributes xfr type = iso 01h 4 wmaxpacketsize (l) maximum packet size = 16 bytes 10h 5 wmaxpacketsize (h) maximum packet size - high 00h 6 binterval polling interval in milliseconds (1 for iso) 01h
page 5-22 chapter 5. ez-usb cpu ez-usb trm v1.9
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-1 6 ez-usb bulk transfers figure 6-1. two bulk transfers, in and out ez-usb provides sixteen endpoints for bulk, control, and interrupt transfers, numbered 0-7 as shown in table 6-1. this chapter describes bulk and interrupt transfers. interrupt transfers are a special case of bulk transfers. ez-usb con- trol endpoint zero is described in chapter 7, "ez-usb endpoint zero." * the highlighted endpoints do not exist in the an2122 or an2126. see also table 1-2. 6.1 introduction table 6-1. ez-usb bulk, control, and interrupt endpoints endpoint direction type size 0 bidir control 64/64 1inbulk/int64 1 out bulk/int 64 2inbulk/int64 2 out bulk/int 64 3inbulk/int64 3 out bulk/int 64 4inbulk/int64 4 out bulk/int 64 5inbulk/int64 5 out bulk/int 64 6inbulk/int64 *6 out bulk/int 64 7 in bulk/int 64 7 out bulk/int 64 i n a d d r e n d p c r c 5 token packet payload data c r c 1 6 data packet a c k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt h/s pkt d a t a 1
page 6-2 chapter 6. ez-usb cpu ez-usb trm v1.9 the usb specification allows maximum packet sizes of 8, 16, 32, or 64 bytes for bulk data, and 1 - 64 bytes for interrupt data. ez-usb provides the maximum 64 bytes of buffer space for each of its sixteen endpoints 0-7 in and 0-7 out. six of the bulk end- points, 2-in, 4-in, 6-in, 2-out, 4-out, and 6-out may be paired with the next consec- utively numbered endpoint to provide double-buffering, which allows one data packet to be serviced by the 8051 while another is in transit over usb. six endpoint pairing bits (usbpair register) control double-buffering. the 8051 sets fourteen endpoint valid bits (in07val, out07val registers) at initializa- tion time to tell the ez-usb core which endpoints are active. the default control endpoint zero is always valid. bulk data appears in ram. each bulk endpoint has a reserved 64-byte ram space, a 7- bit count register, and a 2-bit control and status (cs) register. the 8051 can read one bit of the cs register to determine endpoint busy , and write the other to force an endpoint stall condition. the 8051 should never read or write an endpoint buffer or byte count register while the endpoints busy bit is set. when an endpoint becomes ready for 8051 service, the ez-usb core sets an interrupt request bit. the ez-usb vectored interrupt system separates the interrupt requests by endpoint to automatically transfer control to the isr (interrupt service routine) for the endpoint requiring service. chapter 9, "ez-usb interrupts" fully describes this mecha- nism. figure 6-2 illustrates the registers and bits associated with bulk transfers.
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-3 figure 6-2. registers associated with bulk endpoints 64 byte endpoint buffer 5 in07val usbpair endpoint valid (1=valid) endpoint pairing (1=paired) byte count control & status s b in07irq interrupt request (write 1 to clear) in07ien interrupt enable (1=enabled) in2bc 7 6 4 3 2 1 0 5 7 6 4 3 2 1 0 i23 i45 i67 o23 o45 o67 5 7 6 4 3 2 1 0 initialization in2buf data transfer in2cs interrupt control busy and stall registers associated with a bulk in endpoint (ep2in shown as example) 64 byte endpoint buffer 5 out07val usbpair byte count control & status s b out07irq out07ien out4bc 7 6 4 3 2 1 0 5 7 6 4 3 2 1 0 i23 i45 i67 o23 o45 o67 5 7 6 4 3 2 1 0 out4buf data transfer out4cs interrupt control busy and stall registers associated with a bulk out endpoint (ep4out shown as example) initialization endpoint valid (1=valid) endpoint pairing (1=paired) interrupt enable (1=enabled) interrupt request (write 1 to clear)
page 6-4 chapter 6. ez-usb cpu ez-usb trm v1.9 figure 6-3. anatomy of a bulk in transfer usb bulk in data travels from device to host. the host requests an in transfer by issuing an in token to the ez-usb core, which responds with data when it is ready. the 8051 indicates ready by loading the endpoints byte count register. if the ez-usb core receives an in token for an endpoint that is not ready, it responds to the in token with a nak hand- shake. in the bulk in transfer illustrated in figure 6-3, the 8051 has previously loaded an end- point buffer with a data packet, and then loaded the endpoints byte count register with the number of bytes in the packet to arm the next in transfer. this sets the endpoints busy bit. the host issues an in token (1), to which the usb core responds by transmitting the data in the in endpoint buffer (2). when the host issues an ack (3), indicating that the data has been received error-free, the usb core clears the endpoints busy bit and sets its interrupt request bit. this notifies the 8051 that the endpoint buffer is empty. if this is a multi-packet transfer, the host then issues another in token to get the next packet. if the second in token (4) arrives before the 8051 has had time to fill the endpoint buffer, the ez usb core issues a nak handshake, indicating busy (5). the host continues to send 6.2 bulk in transfers i n a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k i n a d d r e n d p c r c 5 token packet h/s pkt epnin interrupt, innbsy=0 n a k (innbc loaded) .. . h d hd h 1 2 3 4 5 i n a d d r e n d p c r c 5 token packet n a k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt ... load innbc epnin interrupt, innbsy=0 h dhd h 4 5 6 8 7 ... h/s pkt note: h=host, d=device (ez-usb) ... h/s pkt
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-5 in tokens (4) and (7) until the data is ready. eventually, the 8051 fills the endpoint buffer with data, and then loads the endpoints byte count register (innbc) with the number of bytes in the packet (6). loading the byte count re-arms the given endpoint. when the next in token arrives (7) the usb core transfers the next data packet (8). interrupt transfers are handled just like bulk transfers. the only difference between a bulk endpoint and an interrupt endpoint exists in the end- point descriptor, where the endpoint is identified as type interrupt , and a polling interval is specified. the polling interval determines how often the usb host issues in tokens to the interrupt endpoint. suppose 220 bytes are to be transferred to the host using endpoint 2-in. further assume that maxpacketsize of 64 bytes for endpoint 2-in has been reported to the host during enumeration. because the total transfer size exceeds the maximum packet size, the 8051 divides the 220-byte transfer into four transfers of 64, 64, 64, and 28 bytes. after loading the first 64 bytes into in2buf (at 0x7c00), the 8051 loads the byte count register in6bc with the value 64. writing the byte count register instructs the ez-usb core to respond to the next host in token by transmitting the 64 bytes in the buffer. until the byte count register is loaded to arm the in transfer, any in tokens issued by the host are answered by ez-usb with nak (not-acknowledge) tokens, telling the usb host that the endpoint is not yet ready with data. the host continues to issue in tokens to endpoint 2-in until data is ready for transferwhereupon the ez-usb core replaces naks with valid data. when the 8051 initiates an in transfer by loading the endpoints byte count register, the ez-usb core sets a busy bit to instruct the 8051 to hold off loading in2buf until the usb transfer is finished. when the in transfer is complete and successfully acknowl- edged, the ez-usb core resets the endpoint 2-in busy bit and generates an endpoint 2-in interrupt request. if the endpoint 2-in interrupt is enabled, program control automatically vectors to the data transfer routine for further action (autovectoring is enabled by setting aven=1; refer to chapter 9, "ez-usb interrupts"). 6.3 interrupt transfers 6.4 ez-usb bulk in example
page 6-6 chapter 6. ez-usb cpu ez-usb trm v1.9 the 8051 now loads the next 64 bytes into in2buf and then loads the epinbc register with 64 for the next two transfers. for the last portion of the transfer, the 8051 loads the final 28 bytes into in2buf, and loads in2bc with 28. this completes the transfer. the ez-usb core takes care of usb housekeeping chores such as handshake verification. when an endpoint 2-in interrupt occurs, the user is assured that the data loaded by the 8051 into the endpoint buffer was received error-free by the host. the ez-usb core auto- matically checks the handshake information from the host and re-transmits the data if the host indicates an error by not acking. usb bulk out data travels from host to device. the host requests an out transfer by issuing an out token to ez-usb, followed by a packet of data. the ez-usb core then responds with an ack, if it correctly received the data. if the endpoint buffer is not ready to accept data, the ez-usb core discards the hosts out data and returns a nak token, indicating not ready. in response, the host continues to send out tokens and data to the endpoint until the ez-usb core responds with an ack. initialization note when the ez-usb chip comes out of reset, or when the usb host issues a bus reset, the ez-usb core unarms in endpoint 1-7 by setting their busy bits to 0. any in trans- fer requests are nakd until the 8051 loads the appropriate inxbc register(s). the end- point valid bits are not affected by an 8051 reset or a usb reset. chapter 10, "ez-usb resets" describes the various reset conditions in detail. 6.5 bulk out transfers
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-7 figure 6-4. anatomy of a bulk out transfer each ez-usb bulk out endpoint has a byte count register, which serves two purposes. the 8051 reads the byte count register to determine how many bytes were received during the last out transfer from the host. the 8051 writes the byte count register (with any value) to tell the ez-usb core that is has finished reading bytes from the buffer, making the buffer available to accept the next out transfer. the out endpoints come up (after reset) armed , so the byte count register writes are required only for out transfers after the first one. in the bulk out transfer illustrated in figure 6-4, the 8051 has previously loaded the end- points byte count register with any value to arm receipt of the next out transfer. loading the byte count register causes the ez-usb core to set the out endpoints busy bit to 1, indicating that the 8051 should not use the endpoints buffer. the host issues an out token (1), followed by a packet of data (2), which the usb core acknowledges, clears the endpoints busy bit and generates an interrupt request (3). this notifies the 8051 that the endpoint buffer contains valid usb data. the 8051 reads the endpoints byte count register to find out how many bytes were sent in the packet, and transfers that many bytes out of the endpoint buffer. in a multi-packet transfer, the host then issues another out token (4) along with the next data packet (5). if the 8051 has not finished emptying the endpoint buffer, the ez-usb fx o u t a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k o u t a d d r e n d p c r c 5 token packet h/s pkt epnout interrupt, outnbsy=0 n a k .. . dd h h 1 2 3 4 6 o u t a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt load outnbc (any value), causes outnbsy=1 epnout interrupt, outnbsy=0 d hh 7 9 8 h/s pkt h d a t a 0 payload data c r c 1 6 data packet 5 h o u t a d d r e n d p c r c 5 token packet n a k .. . d h 4 6 h/s pkt d a t a 0 payload data c r c 1 6 data packet 5 h (outnbc loaded, outnbsy=1) ... note: h=host, d=device (ez-usb)
page 6-8 chapter 6. ez-usb cpu ez-usb trm v1.9 host issues a nak, indicating busy (6). the data at (5) is shaded to indicate that the usb core discards it, and does not over-write the data in the endpoints out buffer. the host continues to send out tokens (4, 5, and 6) that are greeted by naks until the buffer is ready. eventually, the 8051 empties the endpoint buffer data, and then loads the endpoints byte count register (7) with any value to re-arm the usb core. once armed and when the next out token arrives (8) the usb core accepts the next data packet (9). the ez-usb core takes care of usb housekeeping chores such as crc checks and data toggle pids. when an endpoint 6-out interrupt occurs and the busy bit is cleared, the user is assured that the data in the endpoint buffer was received error-free from the host. the ez-usb core automatically checks for errors and requests the host to re-transmit data if it detects any errors using the built-in usb error checking mechanisms (crc checks and data toggles). the 8051 sets endpoint pairing bits to 1 to enable double-buffering of the bulk endpoint buffers. with double buffering enabled, the 8051 can operate on one data packet while another is being transferred over usb. the endpoint busy and interrupt request bits func- tion identically, so the 8051 code requires little code modification to support double-buff- ering. when an endpoint is paired, the 8051 uses only the even-numbered endpoint of the pair. the 8051 should not use the paired odd endpoint. for example, suppose it is desired to initializing out endpoints when the ez-usb chip comes out of reset, or when the usb host issues a bus reset, the ez-usb core arms out endpoints 1-7 by setting their busy bits to 1. therefore, they are initially ready to accept one out transfer from the host. subsequent out transfers are nakd until the appropriate outnbc register is loaded to re-arm the endpoint. 6.6 endpoint pairing table 6-2. endpoint pairing bits (in the usb pair register) bit 543210 name pr6out pr4out pr2out pr6in pr4in pr2in paired 6 out 4 out 2 out 6 in 4 in 2 in endpoints 7 out 5 out 3 out 7 in 5 in 3 in
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-9 use endpoint 2-in as a double-buffered endpoint. this pairs the in2buf and in3buf buffers, although the 8051 accesses the in2buf buffer only. the 8051 sets pr2in=1 (in the usbpair register) to enable pairing, sets in2val=1 (in the in07val register) to make the endpoint valid, and then uses the in2buf buffer for all data transfers. the 8051 should not write the in3val bit, enable in3 interrupts, access the ep3in buffer, or load the in3bc byte count register. innbsy=1 indicates that both endpoint buffers are in use, and the 8051 should not load new in data into the endpoint buffer. when innbsy=0, either one or both of the buffers is available for loading by the 8051. the 8051 can keep an internal count that increments on epnin interrupts and decrements on byte count loads to determine whether one or two buffers are free. or, the 8051 can simply check for innbsy=0 after loading a buffer (and loading its byte count register to re-arm the endpoint) to determine if the other buffer is free. a bulk in endpoint interrupt request is generated whenever a packet is successfully trans- mitted over usb. the interrupt request is independent of the busy bit. if both buffers are filled and one is sent, the busy bit transitions from 1-0; if one buffer is filled and then sent, the busy bit starts and remains at 0. in either case an interrupt request is generated to tell the 8051 that a buffer is free. note bits 2 and 5 must be set to 0 in the an2122 and an2126 devices. 6.7 paired in endpoint status important note if an in endpoint is paired and it is desired to clear the busy bit for that endpoint, do the following: (a) write any value to the even endpoints byte count register twice , and (b) clear the busy bit for both endpoints in the pair. this is the only code difference between paired and unpaired use of an in endpoint.
page 6-10 chapter 6. ez-usb cpu ez-usb trm v1.9 outnbsy=1 indicates that both endpoint buffers are empty, and no data is available to the 8051. when outnbsy=0, either one or both of the buffers holds usb out data. the 8051 can keep an internal count that increments on epnout interrupts and decre- ments on byte count loads to determine whether one or two buffers contain data. or, the 8051 can simply check for outnbsy=0 after unloading a buffer (and loading its byte count register to re-arm the endpoint) to determine if the other buffer contains data. table 6-3 shows the ram locations for the sixteen 64-byte buffers for endpoints 0-7 in and out. these buffers are positioned at the bottom of the ez-usb register space so that any buffers not used for endpoints can be reclaimed as general purpose data ram. the top of memory for the 8-kb ez-usb part is at 0x1b3f. however, if the endpoints are allocated in ascending order starting with the lowest numbered endpoints, the higher num- bered unused endpoints can effectively move the top of memory to utilize the unused end- point buffer ram as data memory. for example, an application that uses endpoint 1-in, 6.8 paired out endpoint status 6.9 using bulk buffer memory table 6-3. ez-usb endpoint 0-7 buffer addresses endpoint buffer address mirrored in0buf 7f00-7f3f 1f00-1f3f out0buf 7ec0-7eff 1ec0-1eff in1buf 7e80-7ebf 1e80-1ebf out1buf 7e40-7e7f 1e40-1e7f in2buf 7e00-7e3f 1e00-1e3f out2buf 7dc0-7dff 1dc0-1dff in3buf 7d80-7dbf 1d80-1dbf out3buf 7d40-7d7f 1d40-1d7f in4buf 7d00-7d3f 1d00-1d3f out4buf 7cc0-7cff 1cc0-1cff in5buf 7c80-7cbf 1c80-1cbf out5buf 7c40-7c7f 1c40-1c7f in6buf 7c00-7c3f 1c00-1c3f out6buf 7bc0-7bff 1bc0-1bff in7buf 7b80-7bbf 1b80-1bbf out7buf 7b40-7b7f 1b40-1b7f
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-11 2-in/out (paired), 4-in and 4-out can use 0x1b40-0x1cbf as data memory. chapter 3 gives full details of the ez-usb memory map. the ez-usb core automatically maintains the data toggle bits during bulk, control and interrupt transfers. as explained in chapter 1, "introducing ez-usb," the toggle bits are used to detect certain transmission errors so that erroneous data can be re-sent. in certain circumstances, the host resets its data toggle to data0: ? after sending a clear_feature: endpoint stall request to an endpoint. ? after setting a new interface. ? after selecting a new alternate setting. in these cases, the 8051 can directly clear the data toggle for each of the bulk/interrupt/ control endpoints, using the togctl register (figure 6-5). figure 6-5. bulk endpoint toggle control note an2122 endpoint memory starts at 0x1c00 and an2126 endpoint memory starts at address 0x7c00. note uploads or downloads to unused bulk memory can be done only at the mirrored (low) addresses shown in table 6-3. 6.10 data toggle control togctl data toggle control 7fd7 b7 b6 b5 b4 b3 b2 b1 b0 q s r io 0 ep2 ep1 ep0 r r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
page 6-12 chapter 6. ez-usb cpu ez-usb trm v1.9 the io bit selects the endpoint direction (1=in, 0=out), and the ep2-ep1-ep0 bits select the endpoint number. the q bit, which is read-only, indicates the state of the data toggle for the selected endpoint. writing r=1 sets the data toggle to data0, and writing s=1 sets the data toggle to data1. to clear an endpoints data toggle, the 8051 performs the following sequence: ? select the endpoint by writing the value 000d0eee to the togctl register, where d is the direction and eee is the endpoint number. ? clear the toggle bit by writing the value 001d0eee to the togctl register. after step 1, the 8051 may read the state of the data toggle by reading the togctl regis- ter checking bit 7. note at the present writing, there appears to be no reason to set a data toggle to data1. the s bit is provided for generality.
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-13 the following code illustrates the ez-usb registers used for a simple bulk transfer. in this example, 8051 register r1 keeps track of the number of endpoint 2-in transfers and register r2 keeps track of the number of endpoint 2-out transfers (mod-256). every endpoint 2-in transfer consists of 64 bytes of a decrementing count, with the first byte replaced by the number of in transfers and the second byte replaced by the number of out transfers. figure 6-6. example code for a simple (polled) bulk transfer 6.11 polled bulk transfer example 1 start: mov sp,#stack-1 ; set stack 2 mov dptr,#in2buf ; fill ep2in buffer with 3 mov r7,#64 ; decrementing counter 4 fill: mov a,r7 5 movx @dptr,a 6 inc dptr 7 djnz r7,rill 8; 9 mov r1,#0 ; r1 is in token counter 10 mov r2,#0 ; r2 is out token counter 11 mov dptr,#in2bc ; point to ep2 byte count register 12 mov a,#40h ; 64-byte transfer 13 movx @dptr,a ; arm the in2 transfer 14 ; 15 loop: mov dptr,#in2cs ; poll the ep2-in status 16 movx a,@dptr 17 jnb acc.1,servicein2 ; not busy--keep looping 18 mov dptr,#out2cs 19 movx a,@dptr 20 jb acc.1,loop ; ep2out is busy--keep looping 21 ; 22 serviceout2: 23 inc r2 ; out packet counter 24 mov dptr,#out2bc ; load byte count register to re-arm 25 movx @dptr,a ; (any value) 26 sjmp loop 27 ; 28 servicein2: 29 inc r1 ; in packet counter 30 mov dptr,3in2buf ; update the first data byte 31 mov a,r1 ; in ep2in buffer 32 movx @dptr,a 33 inc dptr ; second byte in buffer 34 mov a,r2 ; get number of out packets 35 movx @dptr,a 36 mov dptr,#in2bc ; point to ep2in byte count register 37 mov a,#40h 38 movx @dptr,a ; load bc=64 to re-arm in2 39 sjmp loop 40 ; 41 end
page 6-14 chapter 6. ez-usb cpu ez-usb trm v1.9 the code at lines 2-7 fills the endpoint 2-in buffer with 64 bytes of a decrementing count. two 8-bit counts are initialized to zero at lines 9 and 10. an endpoint 2-in transfer is armed at lines 11-13, which load the endpoint 2-in byte count register in2bc with 64. then the program enters a polling loop at lines 15-20, where it checks two flags for end- point 2 servicing. lines 15-17 check the endpoint 2-in busy bit in in2cs bit 1. lines 18- 20 check the endpoint 2-out busy bit in out2cs bit 1. when busy=1, the ez-usb core is currently using the endpoint buffers and the 8051 should not access them. when busy=0, new data is ready for service by the 8051. for both in and out endpoints, the busy bit is set when the ez-usb core is using the buffers, and cleared by loading the endpoints byte count register. the byte count value is meaningful for in transfers because it tells the ez-usb core how many bytes to transfer in response to the next in token. the 8051 can load any byte count out transfers, because only the act of loading the register is significantloading outnbc arms the out transfer and sets the endpoints busy bit. when an out packet arrives in out2buf, the service routine at lines 22-26 increments r2, loads the byte count (any value) into out2bc to re-arm the endpoint (lines 24-25), and jumps back to the polling routine. this program does not use out2buf data; it sim- ply counts the number of endpoint 2-out transfers. when endpoint 2-in is ready for the 8051 to load another packet into in2buf, the polling loop jumps to the endpoint 2-in service routine at lines 28-39. first, r1 is incremented (line 29). the data pointer is set to in2buf at line 30, and register r1 is loaded into the first byte of the buffer (lines 31-32). the data pointer is advanced to the second byte of in2buf at line 33, and register r2 is loaded into the buffer (lines 34-35). finally, the byte count 40h (64 decimal bytes) is loaded into the byte count register in2bc to arm the next in transfer at lines 36-38, and the routine returns the polling loop. the code in this example is complete, and runs on the ez-usb chip. you may be wonder- ing about the missing step , which reports the endpoint characteristics to the host during the enumeration process. the reason this code runs without any enumeration code is that the ez-usb chip comes on as a fully-functional usb device with certain endpoints already configured and reported to the host. endpoint 2 is included in this default configuration. the full default configuration is described in chapter 5, "ez-usb enumeration and renumeration ? " 6.12 enumeration note
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-15 all usb interrupts activate the 8051 int 2 interrupt. if enabled, int2 interrupts cause the 8051 to push the current program counter onto the stack, and then execute a jump to loca- tion 0x43, where the programmer has inserted a jump instruction to the interrupt service routine (isr). if the aven (autovector enable) bit is set, the ez-usb core inserts a spe- cial byte at location 0x45, which directs the jump instruction to a table of jump instruc- tions which transfer control the endpoint-specific isr. * replaced by ez-usb core if aven=1. the byte inserted by the ez-usb core at address 0x45 depends on which bulk endpoint requires service. table 6-5 shows all int2 vectors, with the bulk endpoint vectors un- shaded. the shaded interrupts apply to all the bulk endpoints. 6.13 bulk endpoint interrupts table 6-4. 8051 int2 interrupt vector location op-code instruction 0x43 02 ljmp 0x44 addrh 0x45 addrl* table6-5. byteinsertedbyez-usbcoreatlocation0x45ifaven=1 interrupt inserted byte at 0x45 sudav 0x00 sof 0x04 sutok 0x08 suspend 0x0c usbres 0x10 reserved 0x14 ep0-in 0x18 ep0-out 0x1c ep1-in 0x20 ep1out 0x24 ep2in 0x28 ep2out 0x2c ep3-in 0x30 ep3-out 0x34 ep4-in 0x38 ep4-out 0x3c ep5-in 0x40 ep5-out 0x44 ep6-in 0x48 ep6-out 0x4c ep7-in 0x50 ep7-out 0x54
page 6-16 chapter 6. ez-usb cpu ez-usb trm v1.9 the vector values are four bytes apart. this allows the programmer to build a jump table to each of the interrupt service routines. note that the jump table must begin on a page (256 byte) boundary because the first vector starts at 00. if autovectoring is not used (aven=0), the ivec register may be directly inspected to determine the usb interrupt source (see section 9.11, "autovector coding"). each bulk endpoint interrupt has an associated interrupt enable bit (in in07ien and out07ien), and an interrupt request bit (in in07irq and out07irq). the interrupt service routine. irq bits are cleared by writing a 1. because all usb registers are accessed using movx@dptr instructions, usb interrupt service routines must save and restore both data pointers, the dps register, and the accumulator before clearing interrupt request bits. this simple (but fully-functional) example illustrates the bulk transfer mechanism using interrupts. in the example program, bulk endpoint 6 is used to loop data back to the host. data sent by the host over endpoint 2-out is sent back over endpoint 2-in. note any usb isr should clear the 8051 int2 interrupt request bit before clearing any of the ez-usb endpoint irq bits, to avoid losing interrupts. interrupts are discussed in more detail in chapter 9, "ez-usb interrupts." individual interrupt request bits are cleared by writing 1 to them to simplify code. for example, to clear the endpoint 2-in irq, simply write 0000100 to in07irq. this will not disturb the other interrupt request bits. do not read the contents of in07irq, logi- cal-or the contents with 01, and write it back . this clears all other pending interrupts because you are writing 1s to them. 6.14 interrupt bulk transfer example
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-17 1. set up the jump table. figure 6-7. interrupt jump table this table contains all of the usb interrupts, even though only the jumps for endpoint 2 are used for the example. it is convenient to include this table in any usb application that uses interrupts. be sure to locate this table on a page boundary (xx00). cseg at 300h ; any page boundary usb_jump_table: ljmp sudav_isr ; setup data available db 0 ; make a 4-byte entry ljmp sof_isr ; sof db 0 ljmp sutok_isr ; setup data loading db 0 ljmp susp_isr ; global suspend db 0 ljmp ures_isr ; usb reset db 0 ljmp spare_isr db 0 ljmp ep0in_isr db 0 ljmp ep0out_isr db 0 ljmp ep1in_isr db 0 ljmp ep1out_isr db 0 ljmp ep2in_isr db 0 ljmp ep2out_isr db 0 ljmp ep3in_isr db 0 ljmp ep3out_isr db 0 ljmp ep4in_isr db 0 ljmp ep4out_isr db 0 ljmp ep5in_isr db 0 ljmp ep5out_isr db 0 ljmp ep6in_isr ; used by this example db 0 ljmp ep6out_isr ; used by this example db 0 ljmp ep7in_isr db 0 ljmp ep7out_isr db 0
page 6-18 chapter 6. ez-usb cpu ez-usb trm v1.9 2. write the int2 interrupt vector. figure 6-8. int2 interrupt vector 3. write the interrupt service routine. put it anywhere in memory and the jump table in step 1 will automatically jump to it. figure 6-9. interrupt service routine (isr) for endpoint 2-out in this example, the isr simply sets the 8051 flag got_ep2_data to indicate to the back- ground program that the endpoint requires service. note that both data pointers and the dps (data pointer select) registers must be saved and restored in addition to the accumu- lator. ; ----------------- ; interrupt vectors ; ----------------- org 43h ; int2 is the usb vector ljmp usb_jump_table ; autovector will replace byte 45 ; ----------------------------- ; usb interrupt service routine ; ----------------------------- ep2out_isr push dps ; save both dptrs, dps, and acc push dpl push dph push dpl1 push dph1 push acc mov a,exif ; clear usb irq (int2) clr acc.4 mov exif,a mov dptr,#out07irq mov a,#01000000b ; a 1 clears the irq bit movx @dptr,a ; clear out2 int request setb got_ep2_data ; set my flag pop acc ; restore vital registers pop dph1 pop dpl1 pop dph pop dpl pop dps reti
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-19 4. write the endpoint 2 transfer program. figure 6-10. background program transfers endpoint 2-out data to endpoint 2-in the main program loop tests the got_ep2_data flag, waiting until it is set by the end- point 2 out interrupt service routine in figure 6-10. this indicates that a new data packet has arrived in out2buf. then the service routine is entered, where the flag is cleared in line 2. the number of bytes received in out2buf is retrieved from the out2bc register (endpoint 2 byte count) and saved in registers r6 and r7 in lines 7-10. the dual data pointers are initialized to the source (out2buf) and destination (in2buf) buffers for the data transfer in lines 15-18. these labels represent the start of the 64-byte buffers for endpoint 2-out and endpoint 2-in, respectively. each byte is read from the out2buf buffer and written to the in2buf buffer in lines 19-25. the saved value of 1 loop: jnb got_ep2_data,loop 2 clr got_ep2_data ; clear my flag 3; 4 ; the user sent bytes to out2 endpoint using the usb control panel. 5 ; find out how many bytes were sent. 6; 7 mov dptr,#out2bc ; point to out2 byte count register 8 movx a,@dptr ; get the value 9 mov r7,a ; stash the byte count 10 mov r6,a ; save here also 11 ; 12 ; transfer the bytes received on the out2 endpoint to the in2 endpoint 13 ; buffer. number of bytes in r6 and r7. 14 ; 15 mov dptr,#out2buf ; first data pointer points to ep2out buffer 16 inc dps ; select the second data pointer 17 mov dptr,#in2buf ; second data pointer points to ep2in buffer 18 inc dps ; back to first data pointer 19 transfer: movx movx get out byte 20 inc dptr ; bump the pointer 21 inc dps ; second data pointer 22 movx @dptr,a ; put into in buffer 23 inc dptr ; bump the pointer 24 inc dps ; first data pointer 25 djnz r7,transfer 26 ; 27 ; load the byte count into in2bc. this arms in in transfer 28 ; 29 mov dptr,#in2bc 30 mov a,r6 ; get other saved copy of byte count 31 movx @dptr,a ; this arms the in transfer 32 ; 33 ; load any byte count into out2bc. this arms the next out transfer. 34 ; 35 mov dptr,#out2bc 36 movx @dptr,a ; use whatever is in acc 37 sjmp loop ; start checking for another out2 packet
page 6-20 chapter 6. ez-usb cpu ez-usb trm v1.9 out2bc is used as a loop counter in r7 to transfer the exact number of bytes that were received over endpoint 2-out. when the transfer is complete, the program loads the endpoint 2-in byte count register in2bc with the number of loaded bytes (from r6) to arm the next endpoint 2-in transfer in lines 29-31. finally, the 8051 loads any value into the endpoint 2 out byte count reg- ister out2bc to arm the next out transfer in lines 35-36. then the program loops back to check for more endpoint 2-out data. 5. initialize the endpoints and enable the interrupts. figure 6-11. initialization routine the initialization routine sets the stack pointer, and enables the ez-usb autovector by setting usbbav.0 to 1. then it enables the endpoint 2-out interrupt, all usb interrupts (int2), and the 8051 global interrupt (ea) and finally clears the flag indicating that end- point 2-out requires service. once this structure is put into place, it is quite easy to service any or all of the bulk end- points. to add service for endpoint 2-in, for example, simply write an endpoint 2-in interrupt service routine with starting address ep2in_isr (to match the address in the jump table in step 1), and add its valid and interrupt enable bits to the init routine. start: mov sp,#stack-1 ; set stack ; ; enable usb interrupts and autovector ; mov dptr,#usbbav ; enable autovector movx a,@dptr,a setb acc.0 ; aven bit is bit 0 movx @dptr,a ; mov dptr,#out07ien ; ep0-7 out int enables register ; mov a,#01000000b ; set bit 6 for ep2out interrupt enable movx @dptr,a ; enable ep2out interrupt ; ; enable int2 and 8051 global interrupts ; setb ex2 ; enable int2 (usb interrupt) setb ea ; enable 8051 interrupts clr got_ep2_data ; clear my flag
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-21 the code in this example is complete, and runs on the ez-usb chip. you may be wonder- ing about the missing step , which reports the endpoint characteristics to the host during the enumeration process. the reason this code runs without any enumeration code is that the ez-usb chip comes on as a fully-functional usb device with certain endpoints already configured and reported to the host. endpoint 2 is included in this default configuration. the full default configuration is described in chapter 5, "ez-usb enumeration and renumeration ? " portions of the above code are not necessary for the default configuration (such as setting the endpoint valid bits) but the code is included to illustrate all of the ez-usb registers used for bulk transfers. 6.15 enumeration note
page 6-22 chapter 6. ez-usb cpu ez-usb trm v1.9 bulk endpoint data is available in 64-byte buffers in ez-usb ram. in some cases it is preferable to access bulk data as a fifo register rather than as a ram. the ez-usb core provides a special data pointer which automatically increments when data is transferred. using this autopointer, the 8051 can access any contiguous block of internal ez-usb ramasafifo. figure 6-12. autopointer registers the 8051 first loads autoptrh and autoptrl with a ram address (for example the address of a bulk endpoint buffer). then, as the 8051 reads or writes data to the data reg- ister autodata, the address is supplied by autoptrh/l, which automatically incre- ments after every read or write to the autodata register. the autoptrh/l registers may be written or read at anytime. these registers maintain the current pointer address, so the 8051 can read them to determine where the next byte will be read or written. 6.16 the autopointer autoptrh autopointer address high 7fe3 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autoptrl autopointer address low 7fe4 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autodata autopointer data 7fe5 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 6. ez-usb cpu page 6-23 the 8051 code example in figure 6-13 uses the autopointer to transfer a block of eight data bytes from the endpoint 4 out buffer to internal 8051 memory. figure 6-13. use of the autopointer as the comment in the penultimate line indicates, the autopointer saves an inc dptr instruction that would be necessary if one of the 8051 data pointers were used to access the out4buf ram data. this improves the transfer time. as described in chapter 8, "ez-usb isochronous transfers," the ez-usb core provides a method for transferring data directly between an internal fifo and external memory in two 8051 cycles (333 ns). the fast transfer mode is active for bulk data when: ? the 8051 sets fblk=1 in the fastxfr register, enabling fast bulk transfers, ? the 8051 dptr points to the autodata register, and ? the 8051 executes a movx a,@dptr or a movx @dptr,a instruction. the 8051 code example in figure 6-14 shows a transfer loop for moving 64 bytes of exter- nal fifo data into the endpoint 4-in buffer. the fastxfr register bits are explained in chapter 8, "ez-usb isochronous transfers." init: mov dptr,#autoptrh mov a,#high(out4buf) ; high portion of out4buf buffer movx @dptr,a ; load outoptrh mov dptr,#autoptrl mov a,#low(out4buf) ; low portion of out4buf buffer address movx @dptr,a ; load autoptrl mov dptr,#autodata ; point to the fifo register mov r0,#80h ; store data in upper 128 bytes of 8051 ram mov r2,#8 ; loop counter ; loop: movx a,@dptr ; get a fifo byte mov @r0,a ; store it inc r0 ; bump destination pointer ; (note: no inc dptr required here) djnz r2,loop ; do it eight times note fastest bulk transfer speed in and out of ez-usb bulk buffers is achieved when the autopointer is used in conjunction with the ez-usb fast transfer mode.
page 6-24 chapter 6. ez-usb cpu ez-usb trm v1.9 figure 6-14. 8051 code to transfer external data to a bulk in buffer this transfer loop takes 19 cycles per loop times 8 passes, or 22 ms (152 cycles). a usb bulk transfer of 64 bytes takes more that 42 ms (64*8*83 ns) of bus time to transfer the data bytes to or from the host. this calculation neglects usb overhead time. from this simple example, it is clear that by using the autopointer and the ez-usb fast transfer mode, the 8051 can transfer data in and out of ez-usb endpoint buffers signifi- cantly faster than the usb can transfer it to and from the host. this means that the ez- usb chip should never be a speed bottleneck in a usb system. it also gives the 8051 ample time for other processing duties between endpoint buffer loads. the autopointer can be used to quickly move data anywhere in ram, not just the bulk endpoint buffers. for example, it can be used to good effect in an application that calls for transferring a block of data into ram, processing the data, and then transferring the data to a bulk endpoint buffer. note the autopointer works only with internal program/data ram. it does not work with memory outside the chip, or with internal ram that is made available when iso- disab=1. see section 8.9.1, "disable iso" for a description of the isodisab bit. mov dptr,#fastxfr ; set up the fast bulk transfer mode mov a,#01000000b ; fblk=1, rpol=0, rm1-0 = 00 movx @dptr,a ; load the fastxfr register init: mov dptr,#autoptrh mov a,high(in4buf) ; high portion of in4buf movx @dptr,a ; load autoptrh mov dptr,#autoptrl mov a,low(in4buf) ; low portion of in4buf buffer address movx @dptr,a ; load autoptrh mov dptr,#autodata ; point to the fifo register mov r7,#8 ; r7 is loop counter, 8 bytes per loop ; loop: movx @dptr,a ; (2) write in fifo using byte from external bus movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again djnz r7,loop ; (3) do eight more, r7 times
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-1 7 ez-usb endpoint zero endpoint zero has special significance in a usb system. it is a control endpoint, and is required by every usb device. only control endpoints accept special setup tokens that the host uses to signal transfers that deal with device control. the usb host sends a repertoire of standard device requests over endpoint zero. these standard requests are fully defined in chapter 9 of the usb specification. this chapter describes how the ez-usb chip handles endpoint zero requests. because the ez-usb chip can enumerate without firmware (see chapter 5, "ez-usb enumeration and renumeration ? "), the ez-usb core contains logic to perform enumer- ation on its own. this hardware assist of endpoint zero operations is make available to the 8051, simplifying the code required to service device requests. this chapter deals with 8051 control of endpoint zero (renum=1, chapter 5), and describes ez-usb resources such as the setup data pointer that simplify 8051 code that handles endpoint zero requests. endpoint zero is the only control endpoint in the ez-usb chip. although con- trol endpoints are bi-directional , the ez-usb chip provides two 64-byte buffers, in0buf and out0buf, which the 8051 handles exactly like bulk endpoint buffers for the data stages of a control transfer. a second 8-byte buffer, setupdat, which is unique to endpoint zero, holds data that arrives in the setup stage of a control trans- fer. this relieves the 8051 programmer of having to keep track of the three control transfer phasessetup, data, and status. the ez-usb core also generates separate interrupt requests for the various transfer phases, further simplifying code. the in0buf and out0buf buffers have two special properties that result from being used by control endpoint zero: ? endpoints 0-in and 0-out are always valid, so the valid bits (lsb of in07val and out07val registers) are permanently set to 1. writing any value to these two bits has no effect, and reading these bits always returns a 1. ? endpoint 0 cannot be paired with endpoint 1, so there is no pairing bit in the usb- pair register for endpoint 0 or 1. 7.1 introduction
page 7-2 chapter 7. ez-usb cpu ez-usb trm v1.9 figure 7-1. a usb control transfer (this one has a data stage) endpoint zero accepts a special setup packet, which contains an 8-byte data structure that provides host information about the control transaction. control transfers include a final status phase, constructed from standard pids (in/out, data1, and ack/nak). some control transactions include all required data in their 8-byte setup data packet. other control transactions require more out data than will fit into the eight bytes, or require in data from the device. these transactions use standard bulk-like trans- fers to move the data. note in figure 7-1 that the data stage looks exactly like a bulk transfer. as with bulk endpoints, the endpoint zero byte count registers must be loaded to ack the data transfer stage of a control transfer. 7.2 control endpoint ep0 8051 clears hsnak bit (writes 1 to it) or sets the stall bit. i n a d d r e n d p c r c 5 token packet d a t a 0 8bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet d a t a 1 data pkt a c k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt s y n c n a k h/s pkt o u t a d d r e n d p c r c 5 token packet c r c 1 6 setup stage sutok interrupt core sets hsnak=1 sudav interrupt data stage ep0-in interrupt ep0-in interrupt status stage d a t a 1 o u t a d d r e n d p c r c 5 token packet c r c 1 6 .... h/s pkt data pkt a c k h/s pkt
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-3 the status stage consists of an empty data packet with the opposite direction of the data stage, or an in if there was no data stage. this empty data packet gives the device a chance to ack or nak the entire control transfer. the 8051 writes a 1 to a bit call hsnak (handshake nak) to clear it and instruct the ez-usb core to ack the status stage. the hsnak bit is used to hold off completing the control transfer until the device has had time to respond to a request. for example, if the host issues a set_interface request, the 8051 performs various housekeeping chores such as adjusting internal modes and re-initializing endpoints. during this time the host issues handshake (status stage) packets to which the ez-usb core responds with naks, indicating busy. when the 8051 completes the desired operation, it sets hsnak=1 (by writing a 1 to the bit) to ter- minate the control transfer. this handshake prevents the host from attempting to use a partially configured interface. to perform an endpoint stall for the data or status stage of an endpoint zero transfer (the setup stage can never stall), the 8051 must set both the stall and hsnak bits for endpoint zero. some control transfers do not have a data stage. therefore the 8051 code that pro- cesses the setup data should check the length field in the setup data (in the 8-byte buffer at setupdat) and arm endpoint zero for the data phase (by loading in0bc or out0bc) only if the length is non-zero. two 8051 interrupts provide notification that a setup packet has arrived, as shown in figure 7-2. figure 7-2. the two interrupts associated with ep0 control transfers the ez-usb core sets the sutokir bit (setup token interrupt request) when the ez- usb core detects the setup token at the beginning of a control transfer. this inter- rupt is normally used only for debug. the ez-usb core sets the sudavir bit (setup data available interrupt request) when the eight bytes of setup data have been received error-free and transferred to eight ez- d a t a 0 8bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet setup stage sutok interrupt sudav interrupt 8ram bytes setupdat
page 7-4 chapter 7. ez-usb cpu ez-usb trm v1.9 usb registers starting at setupdat. the ez-usb core takes care of any re-tries if it finds any errors in the setup data. these two interrupt request bits are set by the ez- usb core, and must be cleared by firmware. an 8051 program responds to the sudav interrupt request by either directly inspecting the eight bytes at setupdat or by transferring them to a local buffer for further process- ing. servicing the setup data should be a high 8051 priority, since the usb specifica- tion stipulates that control transfers must always be accepted and never nakd. it is therefore possible that a control transfer could arrive while the 8051 is still servicing a previous one. in this case the previous control transfer service should be aborted and the new one serviced. the sutok interrupt gives advance warning that a new con- trol transfer is about to over-write the eight setupdat bytes. if the 8051 stalls endpoint zero (by setting the ep0stall and hsnak bits to 1), the ez- usb core automatically clears this stall bit when the next setup token arrives. like all ez-usb interrupt requests, the sutokir and sudavir bits can be directly tested and reset by the cpu (they are reset by writing a 1). thus, if the corresponding interrupt enable bits are zero, the interrupt request conditions can still be directly polled. figure 7-3 shows the ez-usb registers that deal with control transactions over ep0. figure 7-3. registers associated with ep0 control transfers these registers augment those associated with normal bulk transfers over endpoint zero, which are described in chapter 6, "ez-usb bulk transfers." 8 bytes of setup data usbirq interrupt request: t=setup token sutokir d=setup data sudavir usbien global enable: t=setup token sutokie d=setup data sudavie t initialization setupdat data transfer interrupt control registers associated with endpoint zero for handling setup transactions d t d 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 sudptrh sudptrl
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-5 two bits in the usbien (usb interrupt enable) register enable the setup token (sutokie) and setup data interrupts. the actual interrupt request bits are in the usbirq (usb interrupt requests) register. they are called stokir (setup token interrupt request) and sudavir (setup data interrupt request). the ez-usb core transfers the eight setup bytes into eight bytes of ram at setup- dat. a 16-bit pointer, sudptrh/l gives hardware assistance for handling control in transfers, in particular, the usb get_descriptor requests described later in this chapter. the universal serial bus specification version 1.1, chapter 9, "usb device framework" defines a set of standard device requests . when the 8051 is in control (renum=1), the ez-usb core handles one of these requests (set address) directly, and relies on the 8051 to support the others. the 8051 acts on device requests by decoding the eight bytes con- tained in the setup packet. table 7-1 shows the meaning of these eight bytes. the byte column in the previous table shows the byte offset from setupdat. the field column shows the different bytes in the request, where the bm prefix means bit-map, b means byte, and w means word (16 bits). table 7-2 shows the different values defined for brequest, and how the 8051 responds to each request. the remainder of this chapter describes each of the table 7-2 requests in detail. 7.3 usb requests table 7-1. the eight bytes in a usb setup packet byte field meaning 0 bmrequesttype request type, direction, and recipient 1 brequest the actual request (see table 7-2) 2 wvaluel word-size value, varies according to brequest 3 wvalueh 4 windexl word-size field, varies according to brequest 5 windexh 6 wlengthl number of bytes to transfer if there is a data phase 7 wlengthh note table 7-2 applies when renum=1, which signifies that the 8051, and not the ez-usb core, handles device requests. table 5-2 shows how the core handles each of these device requests when renum=0, for example when the chip is first powered and the 8051 is not running.
page 7-6 chapter 7. ez-usb cpu ez-usb trm v1.9 in the renumerated condition (renum=1), the ez-usb core passes all usb requests except set address onto the 8051 via the sudav interrupt. this, in conjunction with the usb disconnect/connect feature, allows a completely new and different usb device (yours) to be characterized by the downloaded firmware. the ez-usb core implements one vendor-specific request, namely firmware load, 0xa0. (the brequest value of 0xa0 is valid only if byte 0 of the request, bmrequest- type, is also x10xxxxx, indicating a vendor-specific request.) the load request is valid at all times, so even after renumeration the load feature maybe used. if your application implements vendor-specific usb requests, and you do not wish to use the firmware load feature, be sure to refrain from using the brequest value 0xa0 for your custom requests. the firmware load feature is fully described in chapter 5, "ez-usb enumeration and renumeration ? ." table 7-2. how the 8051 handles usb device requests (renum=1) brequest name action 8051 response 0x00 get status sudav interrupt supply remwu, selfpwr or stall bits 0x01 clear feature sudav interrupt clear remwu, selfpwr or stall bits 0x02 (reserved) none stall ep0 0x03 set feature sudav interrupt set remwu, selfpwr or stall bits 0x04 (reserved) none stall ep0 0x05 set address update fnaddr register none 0x06 get descriptor sudav interrupt supply table data over ep0-in 0x07 set descriptor sudav interrupt application dependent 0x08 get configuration sudav interrupt send current configuration number 0x09 set configuration sudav interrupt change current configuration 0x0a get interface sudav interrupt supply alternate setting no. from ram 0x0b set interface sudav interrupt change alternate setting no. 0x0c sync frame sudav interrupt supply a frame number over ep0-in vendor requests 0xa0 (firmware load) up/download ram --- 0xa1 - 0xaf sudav interrupt reserved by cypress semiconductor all except 0xa0 sudav interrupt depends on application note to avoid future incompatibilities, vendor requests a0-af (hex) are reserved by cypress semiconductor.
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-7 7.3.1 get status the usb specification version 1.0 defines three usb status requests. a fourth request, to an interface, is indicated in the spec as reserved. the four status requests are: ? remote wakeup (device request) ? self-powered (device request) ? stall (endpoint request) ? interface request (reserved) the ez-usb core activates the sudav interrupt request to tell the 8051 to decode the setup packet and supply the appropriate status information. figure 7-4. data flow for a get_status request i n a d d r e n d p c r c 5 token packet d a t a 0 8bytes setup data c r c 1 6 data packet s e t u p a d d r e n d p c r c 5 token packet d a t a 1 2 bytes c r c 1 6 data packet d a t a 1 data pkt a c k h/s pkt o u t a d d r e n d p c r c 5 token packet c r c 1 6 setup stage sutok interrupt sudav interrupt data stage status stage 8ram bytes setupdat in0buf 64-byte buffer 2 in0bc a c k h/s pkt a c k h/s pkt
page 7-8 chapter 7. ez-usb cpu ez-usb trm v1.9 as figure 7-4 illustrates, the 8051 responds to the sudav interrupt by decoding the eight bytes the ez-usb core has copied into ram at setupdat. the 8051 answers a get_status request (brequest=0) by loading two bytes into the in0buf buffer and load- ing the byte count register in0bc with the value 2. the ez-usb core transmits these two bytes in response to an in token. finally, the 8051 clears the hsnak bit (by writing 1 to it) to instruct the ez-usb core to ack the status stage of the transfer. the following tables show the eight setup bytes for get_status requests. get_status- device queries the state of two bits, remote wakeup and self-powered. the remote wakeup bit indicates whether or not the device is currently enabled to request remote wakeup. remote wakeup is explained in chapter 11, "ez-usb power manage- ment." the self-powered bit indicates whether or not the device is self-powered (as opposed to usb bus-powered). the 8051 returns these two bits by loading two bytes into in0buf, and then loading a byte count of two into in0bc. table 7-3. get status-device (remote wakeup and self-powered bits) byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device 1 brequest 0x00 get status load two bytes into in0buf 2 wvaluel 0x00 3 wvalueh 0x00 byte 0 : bit 0 = self powered bit 4 windexl 0x00 : bit 1 = remote wakeup 5 windexh 0x00 byte 1 : zero 6 wlengthl 0x02 two bytes requested 7 wlengthh 0x00 table 7-4. get status-endpoint (stall bits) byte field value meaning 8051 response 0 bmrequesttype 0x82 in, endpoint load two bytes into in0buf 1 brequest 0x00 get status byte 0 : bit 0 = stall bit for ep(n) 2 wvaluel 0x00 byte 1 : zero 3 wvalueh 0x00 4windexl ep endpoint number ep(n): 5 windexh 0x00 0x00-0x07: out0-out7 6 wlengthl 0x02 two bytes requested 0x80-0x87: in0-in7 7 wlengthh 0x00
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-9 each bulk endpoint (in or out) has a stall bit in its control and status register (bit 0). if the cpu sets this bit, any requests to the endpoint return a stall handshake rather than ack or nak. the get status-endpoint request returns the stall state for the end- point indicated in byte 4 of the request. note that bit 7 of the endpoint number ep (byte 4) specifies direction. endpoint zero is a control endpoint, which by usb definition is bi-directional . therefore, it has only one stall bit. about stall the usb stall handshake indicates that something unexpected has happened. for instance, if the host requests an invalid alternate setting or attempts to send data to a non- existent endpoint, the device responds with a stall handshake over endpoint zero instead of ack or nak. stalls are defined for all endpoint types except isochronous, which do not employ handshakes. every ez-usb bulk endpoint has its own stall bit. the 8051 sets the stall condition for an endpoint by setting the stall bit in the endpoints cs register. the host tells the 8051 to set or clear the stall condition for an endpoint using the set_feature/stall and clear_feature/stall requests. an example of the 8051 setting a stall bit would be in a routine that handles endpoint zero device requests. if an undefined or non-supported request is decoded, the 8051 should stall ep0. (ep0 has a single stall bit because it is a bi-directional endpoint.) once the 8051 stalls an endpoint, it should not remove the stall until the host issues a clear_feature/stall request. an exception to this rule is endpoint 0, which reports a stall condition only for the current transaction, and then automatically clears the stall condi- tion. this prevents endpoint 0, the default control endpoint, from locking out device requests.
page 7-10 chapter 7. ez-usb cpu ez-usb trm v1.9 get_status/interface is easy: the 8051 returns two zero bytes through in0buf and clears the hsnak bit. the requested bytes are shown as reserved (reset to zero) in the usb specification 7.3.2 set feature set feature is used to enable remote wakeup or stall an endpoint. no data stage is required. the only set_feature/device request presently defined in the usb specification is to set the remote wakeup bit. this is the same bit reported back to the host as a result of a get status-device request (table 7-3). the host uses this bit to enable or disable remote wakeup by the device. table 7-5. get status-interface byte field value meaning 8051 response 0 bmrequesttype 0x81 in, endpoint load two bytes into in0buf 1 brequest 0x00 get status byte 0 : zero 2 wvaluel 0x00 byte 1 : zero 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x02 two bytes requested 7 wlengthh 0x00 table 7-6. set feature-device (set remote wakeup bit) byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device set the remote wakeup bit 1 brequest 0x03 set feature 2 wvaluel 0x01 feature selector: remote wakeup 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-11 the only set_feature/endpoint request presently defined in the usb specification is to stall an endpoint. the 8051 should respond to this request by setting the stall bit in the control and status register for the indicated endpoint ep (byte 4 of the request). the 8051 can either stall an endpoint on its own, or in response to the device request. endpoint stalls are cleared by the host clear_feature/stall request. the 8051 should respond to the set_feature/stall request by performing the following steps: 1. set the stall bit in the indicated endpoints cs register. 2. reset the data toggle for the indicated endpoint. 3. for an in endpoint, clear the busy bit in the indicated endpoints cs register. 4. for an out endpoint, load any value into the endpoints byte count register. 5. clear the hsnak bit in the ep0cs register (by writing 1 to it) to terminate the set_feature/stall control transfer. steps 3 and 4 restore the stalled endpoint to its default condition, ready to send or accept data after the stall condition is removed by the host (using a clear_feature/stall request). these steps are also required when the host sends a set_interface request. table 7-7. set feature-endpoint (stall) byte field value meaning 8051 response 0 bmrequesttype 0x02 out, endpoint set the stall bit for the 1 brequest 0x03 set feature indicated endpoint: 2 wvaluel 0x00 feature selector: stall 3 wvalueh 0x00 4 windexl ep ep(n): 5 windexh 0x00 0x00-0x07: out0-out7 6 wlengthl 0x00 0x80-0x87: in0-in7 7 wlengthh 0x00 data toggles the ez-usb core automatically maintains the endpoint toggle bits to ensure data integ- rity for usb transfers. the 8051 should directly manipulate these bits only for a very limited set of circumstances: ? set_feature/stall ? set_configuration ? set_interface
page 7-12 chapter 7. ez-usb cpu ez-usb trm v1.9 7.3.3 clear feature clear feature is used to disable remote wakeup or to clear a stalled endpoint. if the usb device supports remote wakeup (as reported in its descriptor table when the device is enumerated), the clear_feature/remote wakeup request disables the wakeup capability. the clear_feature/stall removes the stall condition from an endpoint. the 8051 should respond by clearing the stall bit in the indicated endpoints cs register. 7.3.4 get descriptor during enumeration, the host queries a usb device to learn its capabilities and require- ments using get_descriptor requests. using tables of descriptors , the device sends back table 7-8. clear feature-device (clear remote wakeup bit) byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device clear the remote wakeup bit 1 brequest 0x01 clear feature 2 wvaluel 0x01 feature selector: remote wakeup 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00 table 7-9. clear feature-endpoint (clear stall) byte field value meaning 8051 response 0 bmrequesttype 0x02 out, endpoint clear the stall bit for the 1 brequest 0x01 clear feature indicated endpoint: 2 wvaluel 0x00 feature selector: stall 3 wvalueh 0x00 4windexl ep ep(n): 5 windexh 0x00 0x00-0x07: out0-out7 6 wlengthl 0x00 0x80-0x87: in0-in7 7 wlengthh 0x00
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-13 (over ep0-in) such information as what device driver to load, how many endpoints it has, its different configurations, alternate settings it may use, and informative text strings about the device. the ez-usb core provides a special setup data pointer to simplify 8051 service for get_descriptor requests. the 8051 loads this 16-bit pointer with the beginning address of the requested descriptor, clears the hsnak bit (by writing 1 to it), and the ez-usb core does the rest. figure 7-5. using the setup data pointer (sudptr) for get_descriptor requests figure 7-5 illustrates use of the setup data pointer. this pointer is implemented as two registers, sudptrh and sudptrl. most get_descriptor requests involve transferring more data than will fit into one packet. in the figure 7-5 example, the descriptor data con- sists of 91 bytes. i n a d d r e n d p c r c 5 token packet d a t a 0 8bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet d a t a 1 payload data c r c 1 6 data packet a c k i n a d d r e n d p c r c 5 token packet d a t a 0 payload data c r c 1 6 data packet a c k h/s pkt setup stage sudav interrupt data stage ep0in interrupt ep0in interrupt status stage d a t a 1 o u t a d d r e n d p c r c 5 token packet c r c 1 6 h/s pkt data pkt a c k h/s pkt sudptrh/l 64 bytes 27 bytes 8ram bytes setupdat
page 7-14 chapter 7. ez-usb cpu ez-usb trm v1.9 the control transaction starts in the usual way, with the ez-usb core transferring the eight bytes in the setup packet into ram at setupdat and activating the sudav interrupt request. the 8051 decodes the get_descriptor request, and responds by clearing the hsnak bit (by writing 1 to it), and then loading the sudptr registers with the address of the requested descriptor. loading the sudptrl register causes the ez-usb core to automatically respond to two in transfers with 64 bytes and 27 bytes of data using sudptr as a base address, and then to respond to (ack) the status stage. the usual endpoint zero interrupts, sudav and ep0in, remain active during this auto- mated transfer. the 8051 normally disables these interrupts because the transfer requires no 8051 intervention. three types of descriptors are defined: device, configuration, and string. 7.3.4.1 get descriptor-device as illustrated in figure 7-5, the 8051 loads the 2-byte sudptr with the starting address of the device descriptor table. when sudptrl is loaded, the ez-usb core performs the following operations: 1. reads the requested number of bytes for the transfer from bytes 6 and 7 of the setup packet ( lenl and lenh in table 7-11). 2. reads the requested strings descriptor to determine the actual string length. 3. sends the smaller of (a) the requested number of bytes or (b) the actual number of bytes in the string, over in0buf using the setup data pointer as a data table table 7-10. get descriptor- device byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device set sudptr h-l to start of 1 brequest 0x06 get_descriptor device descriptor table in ram 2 wvaluel 0x00 3 wvalueh 0x01 descriptor type: device 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-15 index. this constitutes the second phase of the three-phase control transfer. the core packetizes the data into multiple data transfers as necessary. 4. automatically checks for errors and re-transmits data packets if necessary. 5. responds to the third (handshake) phase of the control transfer to terminate the operation. the setup data pointer can be used for any get_descriptor request; for example, get_descriptor-string. it can also be used for vendor-specific requests (that you define), as long as bytes 6-7 contain the number of bytes in the transfer (for step 1). it is possible for the 8051 to do manual control transfers, directly loading the in0buf buffer with the various packets and keeping track of which setup phase is in effect. this would be a good usb training exercise, but not necessary due to the hardware support built into the ez-usb core for control transfers. for data stage transfers of fewer than 64 bytes, moving the data into the in0buf buffer and then loading the ep0inbc register with the byte count would be equivalent to loading the setup data pointer. however, this would waste 8051 overhead because the setup data pointer requires no byte transfers into the in0buf buffer. 7.3.4.2 get descriptor-configuration table 7-11. get descriptor- configuration byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device set sudptr h-l to start of 1 brequest 0x06 get_descriptor configuration descriptor table in 2 wvaluel cfg config number ram 3 wvalueh 0x02 descriptor type: configuration 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh
page 7-16 chapter 7. ez-usb cpu ez-usb trm v1.9 7.3.4.3 get descriptor-string configuration and string descriptors are handled similarly to device descriptors. the 8051 firmware reads byte 2 of the setup data to determine which configuration or string is being requested, loads the corresponding table pointer into sudptrh-l, and the ez- usb core does the rest. 7.3.5 set descriptor table 7-12. get descriptor- string byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device set sudptr h-l to start of 1 brequest 0x06 get_descriptor configuration descriptor table in 2 wvaluel cfg string number ram 3 wvalueh 0x02 descriptor type: string 4 windexl 0x00 (language id l) 5 windexh 0x00 (language id h) 6 wlengthl lenl 7 wlengthh lenh table 7-13. set descriptor- device byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read device descriptor data over 1 brequest 0x07 set_descriptor out0buf 2 wvaluel 0x00 3 wvalueh 0x01 descriptor type: device 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-17 the 8051 handles set_descriptor requests by clearing the hsnak bit (by writing 1 to it), then reading descriptor data directly from the out0buf buffer. the ez-usb core keeps track of the number of byes transferred from the host into out0buf, and compares this number with the length field in bytes 6 and 7. when the proper number of bytes has been transferred, the ez-usb core automatically responds to the status phase, which is the third and final stage of the control transfer. table 7-14. set descriptor- configuration byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read configuration descriptor 1 brequest 0x07 set_descriptor data over out0buf 2 wvaluel 0x00 3 wvalueh 0x02 descriptor type: configuration 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl 7 wlengthh lenh table 7-15. set descriptor- string byte field value meaning 8051 response 0 bmrequesttype 0x00 in, device read string descriptor data over 1 brequest 0x07 get_descriptor out0buf 2 wvaluel 0x00 config number 3 wvalueh 0x03 descriptor type: string 4 windexl 0x00 (language id l) 5 windexh 0x00 (language id h) 6 wlengthl lenl 7 wlengthh lenh note the 8051 controls the flow of data in the data stage of a control transfer. after the 8051 processes each out packet, it loads any value into the out endpoints byte count register to re-arm the endpoint.
page 7-18 chapter 7. ez-usb cpu ez-usb trm v1.9 configurations, interfaces, and alternate settings configurations, interfaces, and alternate settings a usb device has one or more configu- ration . only one configuration is active at any time. a configuration has one or more inter- face , all of which are concurrently active. multiple interfaces allow different host- side device drivers to be associated with different portions of a usb device. each interface has one or more alternate setting . each alternate setting has a col- lection of one or more endpoints. this structure is a software model; the ez-usb core takes no action when these settings change. however, the 8051 must re-initialize endpoints when the host changes config- urations or interfaces alternate settings. as far as 8051 firmware is concerned, a configuration is simply a byte variable that indi- cates the current setting. the host issues a set_coniguration request to select a configuration, and a get_configuration request to determine the current configuration. device config 2 low power config 1 high power interface 1 audio interface 0 cdrom control alt setting 0 alt setting 1 alt setting 3 interface 2 video interface 3 data storage concurrent one at a time ep ep ep one at a time
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-19 7.3.6 set configuration when the host issues the set_configuration request, the 8051 saves the configuration number (byte 2 in table table 7-16), performs any internal operations necessary to sup- port the configuration, and finally clears the hsnak bit (by writing 1 to it) to terminate the set_configuration control transfer. 7.3.7 get configuration the 8051 returns the current configuration number. it loads the configuration number into ep0in, loads a byte count of one into ep0inbc, and finally clears the hshak bit (by writing 1 to it) to terminate the set_configuration control transfer. table 7-16. set configuration byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read and stash byte 2, change 1 brequest 0x09 set_configuration configurations in firmware 2 wvaluel cfg config number 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00 note after setting a configuration, the host issues set_interface commands to set up the vari- ous interfaces contained in the configuration. table 7-17. get configuration byte field value meaning 8051 response 0 bmrequesttype 0x80 in, device send cfg over in0buf after 1 brequest 0x08 get_configuration re-configuring 2 wvaluel 0x00 3 wvalueh 0x00 4 windexl 0x00 5 windexh 0x00 6 wlengthl 1 lenl 7 wlengthh 0 lenh
page 7-20 chapter 7. ez-usb cpu ez-usb trm v1.9 7.3.8 set interface this confusingly named usb command actually sets and reads back alternate settings for a specified interface. usb devices can have multiple concurrent interfaces. for example a device may have an audio system that supports different sample rates, and a graphic control panel that supports different languages. each interface has a collection of endpoints. except for endpoint 0, which each interface uses for device control, endpoints may not be shared between inter- faces. interfaces may report alternate settings in their descriptors. for example, the audio inter- face may have setting 0, 1, and 2 for 8-khz, 22-khz, and 44-khz sample rates, and the panel interface may have settings 0 and 1 for english and spanish. the set/get_interface requests select between the various alternate settings in an interface. the 8051 should respond to a set_interface request by performing the following steps: ? perform the internal operation requested (such as adjusting a sampling rate). ? reset the data toggles for every endpoint in the interface. ? for an in endpoint, clear the busy bit for every endpoint in the interface. ? for an out endpoint, load any value into the byte count register for every end- point in the interface. ? clear the hsnak bit (by writing 1 to it) to terminate the set_feature/stall control transfer. table 7-18. set interface (actually, set alternate setting as for interface if) byte field value meaning 8051 response 0 bmrequesttype 0x00 out, device read and stash byte 2 (as) for 1 brequest 0x0b set_interface interface if, change setting for 2 wvaluel as alt setting number interface if in firmware 3 wvalueh 0x00 4windexl if for this interface 5 windexh 0x00 6 wlengthl 0x00 7 wlengthh 0x00
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-21 7.3.9 get interface the 8051 simply returns the alternate setting for the requested interface if, and clears the hsnak bit by writing 1 to it. 7.3.10 set address when a usb device is first plugged in, it responds to device address 0 until the host assigns it a unique address using the set_address request. the ez-usb core copies this device address into the fnaddr (function address) register, and subsequently responds only to requests to this address. this address is in effect until the usb device is unplugged, the host issues a usb reset, or the host powers down. the fnaddr register can be read, but not written by the 8051. whenever the ez-usb core renumerates ? , it automatically resets the fnaddr to zero allowing the device to come back as new . an 8051 program does not need to know the device address, because the ez-usb core automatically responds only to the host-assigned fnaddr value. the ez-usb core makes it readable by the 8051 for debug/diagnostic purposes. table 7-19. get interface (actually, get alternate setting as for interface if) byte field value meaning 8051 response 0 bmrequesttype 0x81 in, device send as for interface if over 1 brequest 0x0a get_interface out0buf (1 byte) 2 wvaluel 0x00 3 wvalueh 0x00 4 windexl if for this interface 5 windexh 0x00 6 wlengthl 1 lenl 7 wlengthh 0 lenh
page 7-22 chapter 7. ez-usb cpu ez-usb trm v1.9 7.3.11 sync frame the sync_frame request is used to establish a marker in time so the host and usb device can synchronize multi-frame transfers over isochronous endpoints. suppose an isochronous transmission consists of a repeating sequence of five 300 byte packets transmitted from host to device over ep8-out. both host and device maintain sequence counters that count repeatedly from 1 to 5 to keep track of the packets inside a transmission. to start up in sync, both host and device need to reset their counts to 1 at the same time (in the same frame). to get in sync, the host issues the sync_frame request with ep=ep-out (byte 4). the 8051 firmware responds by loading in0buf with a two-byte frame count for some future time; for example, the current frame plus 20. this marks frame current+20 as the sync frame, during which both sides will initialize their sequence counters to 1. the 8051 reads the current frame count in the usbframel and usbframeh registers. multiple isochronous endpoints can be synchronized in this manner. the 8051 keeps sep- arate internal sequence counts for each endpoint. table 7-20. sync frame byte field value meaning 8051 response 0 bmrequesttype 0x82 in, endpoint send a frame number over 1 brequest 0x0c sync_frame in0buf to synchronize endpoint 2 wvaluel 0x00 ep 3 wvalueh 0x00 4windexl ep endpoint number 5 windexh 0x00 ep(n): 6 wlengthl 2 lenl 0x08-0x0f: out8-out15 7 wlengthh 0 lenh 0x88-0x8f: in8-in15 about usb frames the usb host issues a sof (start of frame) packet once every millisecond. every sof packet contains an 11-bit (mod-2048) frame number. the 8051 services all isochronous transfers at sof time, using a single sof interrupt request and vector. if the ez-usb core detects a missing sof packet, it uses an internal counter to generate the sof inter- rupt.
ez-usb trm v1.9 chapter 7. ez-usb cpu page 7-23 7.3.12 firmware load the usb endpoint zero protocol provides a mechanism for mixing vendor-specific requests with the previously described standard device requests. bits 6:5 of the bmre- quest field are set to 00 for a standard device request, and to 10 for a vendor request. the ez-usb core responds to two endpoint zero vendor requests, ram download and ram upload. these requests are active in all modes (renum=0 or 1). because bit 7 of the first byte of the setup packet specifies direction, only one brequest value (0xa0) is required for the upload and download requests. these ram load com- mands are available to any usb device that uses the ez-usb chip. a host loader program typically writes 0x01 to the cpucs register to put the 8051 into reset, loads all or part of the ez-usb internal ram with 8051 code, and finally reloads the cpucs register with 0 to take the 8051 out of reset. the cpucs register is the only usb register that can be written using the firmware download command. table 7-21. firmware download byte field value meaning 8051 response 0 bmrequesttype 0x40 vendor request, out none required 1 brequest 0xa0 firmware load 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl number of bytes 7 wlengthh lenh table 7-22. firmware upload byte field value meaning 8051 response 0 bmrequesttype 0xc0 vendor request, in none required 1 brequest 0xa0 firmware load 2 wvaluel addrl starting address 3 wvalueh addrh 4 windexl 0x00 5 windexh 0x00 6 wlengthl lenl number of bytes 7 wlengthh lenh
page 7-24 chapter 7. ez-usb cpu ez-usb trm v1.9
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-1 8 ez-usb isochronous transfers isochronous endpoints typically handle time-critical, streamed data that is delivered or consumed in byte-sequential order. examples might be audio data sent to a dac over usb, or teleconferencing video data sent from a camera to the host. due to the byte- sequential nature of this data, the ez-usb chip makes isochronous data available as a sin- gle byte that represents the head or tail of an endpoint fifo. the ez-usb chips that support isochronous transfers implement sixteen isochronous end- points, in8-in15 and out8-out15. 1,024 bytes of fifo memory may be distributed over the 16 endpoint addresses. fifo sizes for the isochronous endpoints are programma- ble. figure 8-1. ez-usb isochronous endpoints 8-15 the 8051 reads or writes isochronous data using sixteen fifo data registers, one per end- point. these fifo registers are shown in figure 8-1 as inndata (endpoint n in data) and outndata (endpoint n out data). the ez-usb core provides a total of 2,048 bytes of fifo memory (1,024 bytes, double- buffered) for iso endpoints. this memory is in addition to the 8051 program/data mem- ory, and normally exists outside of the 8051 memory space. the 1,024 fifo bytes may be divided among the sixteen isochronous endpoints. the 8051 writes sixteen ez-usb reg- isters to allocate the fifo buffer space to the isochronous endpoints. the 8051 also sets endpoint valid bits to enable isochronous endpoints. 8.1 introduction outndata register usb out data usb in data 8051 fifo usb fifo 8051 fifo usb fifo inndata register sof sof (n=8-15) (n=8-15)
page 8-2 chapter 8. ez-usb cpu ez-usb trm v1.9 in transfers travel from device to host. figure 8-2 shows the ez-usb registers and bits associated with isochronous in transfers. figure 8-2. isochronous in endpoint registers 8.2.1 initialization to initialize an isochronous in endpoint, the 8051 performs the following: ? sets the endpoint valid bit for the endpoint. ? sets the endpoints fifo size by loading a starting address (section 8.4, "setting isochronous fifo sizes"). ? sets the isosend0 bit in the usbpair register for the desired response. ? enables the sof interrupt. all isochronous endpoints are serviced in response to the sof interrupt. 8.2 isochronous in transfers 13 inisoval 0 endpoint valid (1=valid) usbien sofie (1=enabled) in8data 15 14 12 11 8 10 9 5 7 6 4 3 1 2 0 initialization data transfer registers associated with an iso in endpoint (ep8in shown as example) usbirq sofir (1=clear request) 5 7 6 4 3 1 2 0 1 2 3 4 5 6 7 data to usb usbpair isosend0 (see text) 5 2 6 4 3 7 1 0 in8addr fifo start address (see text) a7 a4 a8 a6 a5 a9 0 0
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-3 the ez-usb core uses the isosend0 bit to determine what to do if: ? the 8051 does not load any bytes to an inndata register during the previous frame, and ? an in token for that endpoint arrives from the host. if isosend0=0 (the default value), the ez-usb core does not respond to the in token. if isosend0=1, the ez-usb core sends a zero-length data packet in response to the in token. which action to take depends on the overall system design. the isosend0 bit applies to all of the isochronous in endpoints, ep8in through ep15in. 8.2.2 in data transfers when an sof interrupt occurs, the 8051 is presented with empty in fifos that it fills with data to be transferred to the host during the next frame. the 8051 has 1 ms to transfer data into these fifos before the next sof interrupt arrives. to respond to the sof interrupt, the 8051 clears the usb interrupt (8051 int2), and clears the sofir (start of frame interrupt request) bit writing a 1 to it. then, the 8051 loads data into the appropriate isochronous endpoint. the ez-usb core keeps track of the number of bytes the 8051 loads to each inndata register, and subsequently transfers the correct number of bytes in response to the usb in token during the next frame. the ez-usb fifo swap occurs every sof, even if during the previous frame the host did not issue an in token to read the isochronous fifo data, or if the host encountered an error in the data. usb isochronous data has no re-try mechanism like bulk data. out transfers travel from host to device. figure 8-3 shows the ez-usb registers and bits associated with isochronous out transfers. 8.3 isochronous out transfers
page 8-4 chapter 8. ez-usb cpu ez-usb trm v1.9 figure 8-3. isochronous out registers 8.3.1 initialization to initialize an isochronous out endpoint, the 8051: ? sets the endpoint valid bit for the endpoint. ? sets the endpoints fifo size by loading a starting address (section 8.4, "setting isochronous fifo sizes"). ? enables the sof interrupt. all isochronous endpoints are serviced in response to the sof interrupt. 8.3.2 out data transfer when an sof interrupt occurs, the 8051 is presented with fifos containing out data sent from the host in the previous frame, along with 10-bit byte counts, indicating how many bytes are in the fifos. the 8051 has 1 ms to transfer data out of these fifos before the next sof interrupt arrives. registers associated with an iso out endpoint (ep15out shown as example) 13 outisoval endpoint valid (1=valid) usbien sofie (1=enabled) 8 14 12 11 15 10 9 5 7 6 4 3 1 2 0 initialization 0 out15data data transfer usbirq sofir (1=clear request) 5 7 6 4 3 1 2 0 1 2 3 4 5 6 7 received byte count (h) 8 9 2 3 4 5 6 7 received byte count (l) 0 1 2 3 4 5 6 7 out15bch out15bcl isoerr out15 crc error (1=error) 13 10 14 12 11 15 9 8 data from usb out15addr fifo start address (see text) a7 a4 a8 a6 a5 a9 0 0
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-5 to respond to the sof interrupt, the 8051 clears the usb interrupt (8051 int2), and clears the sofir bit by writing one to it. then, the 8051 reads data from the appropriate outndata fifo register(s). the 8051 can check an error bit in the isoerr register to determine if a crc error occurred for the endpoint data. isochronous data is never present, so the firmware must decide what to do with bad-crc data. up to sixteen ez-usb isochronous endpoints share an ez-usb 1,024-byte ram which can be configured as one to sixteen fifos. the 8051 initializes the endpoint fifo sizes by specifying the starting address for each fifo within the 1,024 bytes, starting at address zero. the isochronous fifos can exist anywhere in the 1,024 bytes, but the user must take care to ensure that there is sufficient space between start addresses to accommodate the endpoint fifo size. sixteen start address registers set the isochronous fifo sizes (table 8-1). the ez-usb core constructs the address writing the 1,024 byte range from the register value as shown in figure 8-4. figure 8-4. fifo start address format 8.4 setting isochronous fifo sizes a9 a8 a7 a6 a5 a4 0 0 0 0 register address
page 8-6 chapter 8. ez-usb cpu ez-usb trm v1.9 the size of an isochronous endpoint fifo is determined by subtracting consecutive addresses in table 8-1, and multiplying by four. values written to these registers should have the two lsbs set to zero. the last endpoint, ep15in, has a size of 1,024 minus in15addr times four. because the 10-bit effective address has the four lsbs set to zero (figure 8-4), the fifo sizes are allocated in increments of 16 bytes. for example, if out8addr=0x00 and out9addr=0x04, ep8out has a fifo size of the difference multiplied by four or 16 bytes. an 8051 assembler or c compiler may be used to translate fifo sizes into starting addresses. the assembler example in figure 8-5 shows a block of equates for the 16 iso- chronous fifo sizes, followed by assembler equations to compute the corresponding fifo relative address values. to initialize all sixteen fifo sizes, the 8051 merely copies the table starting at 8outad to the sixteen ez-usb registers starting at out8addr. table 8-1. isochronous endpoint fifo starting address registers register function b7 b6 b5 b4 b3 b2 b1 b0 out8addr endpoint 8 out start address a9 a8 a7 a6 a5 a4 0 0 out9addr endpoint 9 out start address a9 a8 a7 a6 a5 a4 0 0 out10addr endpoint 10 out start address a9 a8 a7 a6 a5 a4 0 0 out11addr endpoint 11 out start address a9 a8 a7 a6 a5 a4 0 0 out12addr endpoint 12 out start address a9 a8 a7 a6 a5 a4 0 0 out13addr endpoint 13 out start address a9 a8 a7 a6 a5 a4 0 0 out14addr endpoint 14 out start address a9 a8 a7 a6 a5 a4 0 0 out15addr endpoint 15 out start address a9 a8 a7 a6 a5 a4 0 0 in8addr endpoint 8 in start address a9 a8 a7 a6 a5 a4 0 0 in9addr endpoint 9 in start address a9 a8 a7 a6 a5 a4 0 0 in10addr endpoint 10 in start address a9 a8 a7 a6 a5 a4 0 0 in11addr endpoint 11 in start address a9 a8 a7 a6 a5 a4 0 0 in12addr endpoint 12 in start address a9 a8 a7 a6 a5 a4 0 0 in13addr endpoint 13 in start address a9 a8 a7 a6 a5 a4 0 0 in14addr endpoint 14 in start address a9 a8 a7 a6 a5 a4 0 0 in15addr endpoint 15 in start address a9 a8 a7 a6 a5 a4 0 0
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-7 figure 8-5. assembler translates fifo sizes to addresses the assembler computes starting addresses in figure 8-5 by adding the previous end- points address to the desired size shifted right twice. this aligns a9 with bit 7 as shown in table 8-1. the low operator takes the low byte of the resulting 16 bit expression the user of this code must ensure that the sizes given in the first equate block are all mul- tiples of 16. this is easy to tell by inspectionthe least significant digit of the hex values in the first column should be zero. 0100 ep8insz equ 256 ; iso fifo sizes in bytes 0100 ep8outsz equ 256 0010 ep9insz equ 16 0010 ep9outsz equ 16 0010 ep10insz equ 16 0010 ep10outsz equ 16 0000 ep11insz equ 0 0000 ep11outsz equ 0 0000 ep12insz equ 0 0000 ep12outsz equ 0 0000 ep13insz equ 0 0000 ep13outsz equ 0 0000 ep14insz equ 0 0000 ep14outsz equ 0 0000 ep15insz equ 0 0000 ep15outsz equ 0 ; 0000 8outad equ 0 ; load these 16 bytes into addr regs starting out8addr 0040 9outad equ 8outad + low(ep8outsz/4) 0044 10outad equ 9outad + low(ep9outsz/4) 0048 11outad equ 10outad + low(ep10outsz/4) 0048 12outad equ 11outad + low(ep11outsz/4) 0048 13outad equ 12outad + low(ep12outsz/4) 0048 14outad equ 13outad + low(ep13outsz/4) 0048 15outad equ 14outad + low(ep14outsz/4) 0048 8inad equ 15outad + low(ep15outsz/4) 0088 9inad equ 8inad + low(ep8insz/4) 008c 10inad equ 9inad + low(ep9insz/4) 0090 11inad equ 10inad + low(ep10insz/4) 0090 12inad equ 11inad + low(ep11insz/4) 0090 13inad equ 12inad + low(ep12insz/4) 0090 14inad equ 13inad + low(ep13insz/4) 0090 15inad equ 14inad + low(ep14insz/4)
page 8-8 chapter 8. ez-usb cpu ez-usb trm v1.9 the amount of data usb can transfer during a 1-ms frame is slightly more than 1,000 bytes per frame (1,500 bytes theoretical, without accounting for usb overhead and bus utilization). a devices actual isochronous transfer bandwidth is usually determined by how fast the cpu can move data in and out of its isochronous endpoint fifos. the 8051 code example in figure 8-6 shows a typical transfer loop for moving external fifo data into an in endpoint fifo. this code assumes that the 8051 is moving data from an external fifo attached to the ez-usb data bus and strobed by the rd signal, into an internal isochronous in fifo. figure 8-6. 8051 code to transfer data to an isochronous fifo (in8data) the numbers in parentheses indicate 8051 cycles. one cycle is four clocks, and the ez- usb 8051 is clocked at 24 mhz (42 ns). thus, an 8051 cycle takes 4*42=168 ns, and the loop takes 9 cycles or 1.5 m s. this loop can transfer about 660 bytes into an in fifo every millisecond (1 ms/1.5 m s). if more speed is required, the loop can be unrolled by in-line coding the first four instruc- tions in the loop. then, a byte is transferred in 6 cycles (24 clocks) which equates to 1 m s per byte. using this method, the 8051 could transfer 1,000 bytes into an in fifo every millisecond. in practice, a better solution is to in-line code only a portion of the loop code, which decreases full in-line performance only slightly and uses far fewer bytes of program code. 8.5 isochronous transfer speed mov dptr,#8000h ; pointer to any outside address inc dps ; switch to second data pointer mov dptr,#in8data ; pointer to an in endpoint fifo (in8 as example) inc dps ; back to first data pointer mov r7,#nbytes ; r7 is loop countertransfer this many bytes ; loop: movx a,@dptr ; (2) read byte from external bus to acc inc dps ; (1) switch to second data pointer movx @dptr,a ; (2) write to iso fifo inc dps ; (1) switch back to first data pointer djnz r7,loop ; (3) loop nbytes times
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-9 ez-usb has a special fast transfer mode for applications that use external fifos con- nected to the ez-usb data bus. these applications typically require very high transfer speeds in and out of ez-usb endpoint buffers. figure 8-7. 8051 movx instructions the 8051 transfers data to and from ez-usb registers and ram using the movx (move external) instruction (figure 8-7). the 8051 loads one of its two 16-bit data pointers (dptr) with an address in ram, and then executes a movx instruction to transfer data between the accumulator and the byte addressed by dptr. the @ symbol indicates that the address is supplied indirectly, by the dptr. the ez-usb core monitors movx transfers between the accumulator and any of the six- teen isochronous fifo registers . if an enable bit is set (fiso=1 in the fastxfr regis- ter), any read or write to an isochronous fifo register causes the ez-usb core to connect the data to the ez-usb data bus d[7..0], and generate external read/write strobes. one movx instruction thus transfers a byte of data in or out of an endpoint fifo and gener- ates timing strobes for an outside fifo or memory. the 2-cycle movx instruction takes 2 cycles or 333 ns. figures 8-8 and 8-9 show the data flow for fast writes and reads over the ez-usb data bus. 8.6 fast transfers movx @dptr,a accumulator dptr ez-usb registers (addressed as external ram) movx a,@dptr
page 8-10 chapter 8. ez-usb cpu ez-usb trm v1.9 8.6.1 fast writes figure 8-8. fast transfer, ez-usb to outside memory fast writes are illustrated in figure 8-8. when the fast mode is enabled, the dptr points to an isochronous out fifo register, and the 8051 executes the movx a,@dptr instruc- tion, the ez-usb core broadcasts the data from the isochronous fifo to the outside world via the data bus d[7..0], and generates a write strobe fwr# (fast write). a choice of eight waveforms is available for the write strobe, as shown in the next section. fast bulk transfers the ez-usb core provides a special auto-incrementing data pointer that makes the fast transfer mechanism available for bulk transfers. the 8051 loads a 16-bit ram address into the autoptrh/l registers, and then accesses ram data as a fifo using the autodata register. section 6.16, "the autopointer" describes this special pointer and register. accumulator dptr iso out fifo fwr# movx a,@dptr d[7..0] external fifo or asic
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-11 8.6.2 fast reads figure 8-9. fast transfer, outside memory to ez-usb fast reads are illustrated in figure 8-9. when the fast mode is enabled, the dptr points to an isochronous out fifo register, and the 8051 executes the movx @dptr,a instruc- tion, the ez-usb core breaks the data path from the accumulator to the in fifo register, and instead writes the in fifo using outside data from d[7..0]. the ez-usb core syn- chronizes this transfer by generating a fifo read strobe frd# (fast read). a choice of eight waveform is available for the read strobe, as shown in the next section. the 8051 sets bits in the fastxfr register to select the fast iso and/or fast bulk mode and to adjust the timing and polarity of the read and write strobes frd# and fwr#. figure 8-10. the fastxfr register controls frd# and fwr# strobes the 8051 sets fiso=1 to select the fast iso mode and fblk=1 to select the fast bulk mode. the 8051 selects read and write strobe pulse polarities with the rpol and wpol bits, where 0=active low, and 1=active high. read and write strobe timings are set by 8.7 fast transfer timing fastxfr fast transfer control 7fe2 b7 b6 b5 b4 b3 b2 b1 b0 fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 accumulator dptr iso in fifo d[7..0] movx @dptr,a frd# external fifo or asic
page 8-12 chapter 8. ez-usb cpu ez-usb trm v1.9 rmod1-rmod0 for read strobes and wmod1-wmod0 for write strobes, as shown in figure 8-11 (write) and figure 8-12 (read). 8.7.1 fast write waveforms figure 8-11. fast write timing note when using the fast transfer feature, be sure to enable the frd# and fwr# strobe sig- nals in the portacfg register. clk24 fwr#[00] d[7..0] output tcl 41.66 ns fwr#[01] fwr#[10] fwr#[11] fwr#[00] d[7..0] output fwr#[01] fwr#[10] fwr#[11] n ote: if w po l=1 the w aveform s are inverted stretch=000 stretch=000 stretch=000 stretch=000 stretch=000 stretch=001 stretch=001 stretch=001 stretch=001 stretch=001 [nn] = wm1:wm0, wpol=0
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-13 the timing choices for fast write pulses (fwr#) are shown in figure 8-11. the 8051 can extend the output data and widths of these pulses by setting cycle stretch values greater than zero in the 8051 clock control register ckcon (at sfr location 0x8e). the top five waveforms show the fastest write timings, with a stretch value of 000, which per- forms the write in eight 8051 clocks. the bottom five waveforms show the same wave- forms with a stretch value of 001. 8.7.2 fast read waveforms figure 8-12. fast read timing the timing choices for fast read pulses (frd#) are shown in figure 8-12. read strobe waveforms for stretch values of 000 and 001 are indicated. although two of the read strobe widths can be extended using stretch values greater than 000, the times that the input data is sampled by the ez-usb core remains the same as shown. osc24 frd#[00] d[7..0] in tcl 41.66 ns frd#[10] frd#[11] d[7..0] in d[7..0] d[7..0] in in frd#[01] frd#[10] frd#[11] stretch=000, 001 stretch=000, 001 stretch=000 stretch=001 stretch=000 stretch=001 note: if wpol=1 the waveforms are inverted [nn] = rmod1:rmod0, rpol=0
page 8-14 chapter 8. ez-usb cpu ez-usb trm v1.9 frd# strobes[00] and [01], along with the osc24 clock signal are typically used to con- nect to an external synchronous fifo. the on-clock-wide read strobe ensures that the fifo address advances only once per clock. the second strobe [01] is for fifos that put data on the bus one clock after the read strobe. stretch values above 000 serve only to extend the 8051 cycle times, without affecting the width of the frd# strobe. frd# strobes [10] and [11] are typically connected to an external asynchronous fifo, where no clock is required. strobe [10] samples the data at the same time as strobe [11], but provides a wider pulse width (for stretch=000), which is required by some audio codecs. timing values for these strobe signals are given in chapter 13, ez-usb ac/ dc parameters. the 8051 code example in figure 8-13 shows a transfer loop for moving external fifo data into the endpoint 8-in fifo. this code moves data from an external fifo attached to the ez-usb data bus and strobed by the frd# signal, into the fifo register in8data figure 8-13. 8051 code to transfer 640 bytes of external data to an isochronous in fifo this routine uses a combination of in-line and looped code to transfer 640 bytes into the ep8in fifo from an external fifo. the loop transfers eight bytes in 19 cycles, and it takes 80 times through the loop to transfer 640 bytes. therefore, the total transfer time is 80 times 19 cycles, or 1,520 cycles. the 640 byte transfer thus takes 1,520*166 ns or 252 m s, or approximately one-fourth of the 1-ms usb frame time. using this routine, the time to completely fill one isochronous fifo with 1,024 bytes (assuming all 1,024 isochronous fifo bytes are assigned to one endpoint) would be 128 8.8 fast transfer speed (init) mov dptr,#fastxfr ; set up the fast iso transfer mode mov a,#10000000b ; fiso=1, rpol=0, rm1-0 = 00 movx @dptr,a ; load the fastxfr register mov dptr,#in8data ; pointer to in endpoint fifo mov r7,#80 ; r7 is loop counter, 8 bytes per loop ; loop: movx @dptr,a ; (2) write in fifo using byte from external bus movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again movx @dptr,a ; (2) again djnz r7,loop ; (3) do eight more, r7 times
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-15 times 19 cycles, or 2,432 cycles. the 1,024 byte transfer would take 403 m s, less than half of the 1-ms usb frame time. if still faster time is required, the routine can be modified to put more of the movx instructions in-line. for example, with 16 in-line movx instructions, the transfer time for 1,024 bytes would be 35 cycles times 64 loops or 2,240 cycles, or 371 m s, an 8% speed improvement over the eight instruction loop. two additional registers, isoctl and zbcout, provide additional isochronous endpoint features. 8.9.1 disable iso figure 8-14. isoctl register bit zero of the isoctl register is called isodisab. when the 8051 sets isodisab=1, all sixteen of ez-usb endpoints are disabled. if isodisab=1, ep8in=ep15in and ep8out-ep15out should not be used. isodisab is cleared at power-on. when isodisab=1, the 2,048 bytes of ram normally used for isochronous buffers is available to the 8051 as xdata ram ( not program memory), from 0x2000 to 0x27ff in internal memory. when isodisab=1, the behavior of the rd# and wr# strobe signals changes to reflect the additional 2 kb of memory inside the ez-usb chip. this is shown in table 8-2. 8.9 other isochronous registers isoctl isochronous control 7fa1 b7 b6 b5 b4 b3 b2 b1 b0 - - - - ppstat mbz mbz isodisab table 8-2. addresses for rd# and wr# vs. isodisab bit isodisab rd#, wr# 0 (default) 2000-7b40, 8000-ffff 1 2800 -7b40, 8000-ffff
page 8-16 chapter 8. ez-usb cpu ez-usb trm v1.9 isoctl register bits shown as mbz (must be zero) must be written with zeros. the ppstat bit toggles every sof, and may be written with any value (no effect). therefore, to disable the isochronous endpoints, the 8051 should write the value 0x01 to the isoctl register. 8.9.2 zero byte count bits when the sof interrupt is asserted, the 8051 normally checks the isochronous out end- point fifos for data. before reading the byte count registers and unloading an isochro- nous fifo, the firmware may wish to check for a zero byte count. in this case, the 8051 can check bits in the zbcout register. any endpoint bit set to 1 indicates that no out bytes were received for that endpoint during the previous frame. figure 8-15 shows this register. figure 8-15. zbcout register the ez-usb core updates these bits every sof. caution! if you use this option, be absolutely certain that the host never sends isochronous data to your device. isochronous data directed to a disabled isochronous endpoint system will cause unpredictable operation. note the autopointer is not usable from 0x2000-0x27ff (the reclaimed iso buffer ram) when isodisab=1. zbcout zero byte count bits 7fa2 b7 b6 b5 b4 b3 b2 b1 b0 ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8
ez-usb trm v1.9 chapter 8. ez-usb cpu page 8-17 the isosend0 bit (bit 7 in the usbpair register) is used when the ez-usb chip receives an isochronous in token while the in fifo is empty. if isosend0=0 (the default value) the ez-usb core does not respond to the in token. if isosend0=1, the ez-usb core sends a zero-length data packet in response to the in token. which action to take depends on the overall system design. the isosend0 bit applies to all of the isoch- ronous in endpoints, in-8 through in-15. there is a window of time before and after each sof (start of frame) when accessing the isochronous fifos will cause data corruption or loss of data. this is because each isochronous endpoint is actually a pair of fifos, and the fifos are swapped at sof time. the swap occurs about 10 m s before the sof interrupt signals the 8051 code. (between sofs, one fifo of the pair is accessible to the 8051, while the other fifo of the pair transfers data to or from the usb.) workaround#1: if you can pre-assemble the data into a buffer, blast the data (in a tight loop) into the new fifo just after the sof interrupt, typically inside the sof isr (inter- rupt service routine). workaround#2: if you cant pre-assemble the data into a buffer, prevent access during sofs by setting a time (in the sof isr) to time out and halt access just before the next sof. set the timer for about 950 m s (ms minus 50 m s). be careful of interrupt latency delaying the timeout isr. that is, the timeout isr may be prevented from halting access by getting preempted by a higher priority interrupt(s), made worse by the necessary practice of disabling interrupts to manage shared resources, resources that are shared between the isrs and background process. to prevent drift of the timer relative to sofs, restart the timer after each sof (typically in the sof isr). 8.10 iso in response with no data 8.11 using the isochronous fifos
page 8-18 chapter 8. ez-usb cpu ez-usb trm v1.9
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-1 9 ez-usb interrupts the ez-usb enhanced 8051 responds to the interrupts shown in table 9-1. interrupt sources that are not present in the standard 8051 are shown as checked in the new col- umn. the three interrupts used by the ez-usb core are shown in bold type. the natural priority column in table 9-1 shows the 8051 interrupt priorities. as explained in appendix c, the 8051 can assign each interrupt to a high or low priority group. the 8051 resolves priorities within the groups using the natural priorities. the ez-usb core provides three interrupt request types, which are described in the fol- lowing sections: wakeup - after the ez-usb chip detects usb suspend and the 8051 has entered its idle state, the ez-usb core responds to an external signal on its wakeup# pin or resumption of usb bus activity by re-starting the ez- usb oscillator and resuming 8051 operation. 9.1 introduction table 9-1. ez-usb interrupts new 8051 interrupt (irq name) source vector (hex) natural priority ie0 int0# pin 03 1 tf0 timer 0 overflow 0b 2 ie1 int1# pin 13 3 tf1 timer 1 overflow 1b 4 ri_0 & ti_0 uart0 rx & tx 23 5 p tf2 timer 2 overflow 2b 6 p resume (pfi) wakeup# pin or usb core 33 0 p ri_1 & ti_1 uart1 rx & tx 3b 7 p usb (int2) usb core 43 8 p i 2 c(int3) usb core 4b 9 p ie4 in4 pin 53 10 p ie5 int5# pin 5b 11 p ie6 int6 pin 63 12 9.2 usb core interrupts
page 9-2 chapter 9. ez-usb interrupts ez-usb trm v1.9 usb signaling - these include 16 bulk endpoint interrupts, three interrupts not specific to a particular endpoint (sof), suspend, usb reset), and two interrupts for control transfers (sutok, sudav). these interrupts share the usb interrupt (int2). the an2122/26 versions have an inter- rupt indicating that a bulk packet was nakd. i 2 c transfers - (int3). chapter 10, "ez-usb resets" describes suspend-resume signaling in detail, along with a code example that uses the wakeup interrupt. briefly, the usb host puts a device into suspend by stopping bus activity to the device. when the ez-usb core detects 3 ms of no bus activity, it activates the usb suspend inter- rupt request. if enabled, the 8051 takes the suspend interrupt, does power management housekeeping (shutting down power to external logic), and finishes by setting sfr bit pcon.0. this signals the ez-usb core to enter a very low power mode by turning off the 12-mhz oscillator. when the 8051 sets pcon.0, it enters an idle state. 8051 execution is resumed by activa- tion of any enabled interrupt. the ez-usb chip uses a dedicated interrupt for usb resume. when external logic pulls wakeup# low (for example, when a keyboard key is pressed or a modem receives a ring signal) or usb bus activity resumes, the ez-usb core re-starts the 12-mhz oscillator, allowing the 8051 to recognize the interrupt and continue executing instructions. figure 9-1. ez-usb wakeup interrupt figure 9-1 shows the 8051 sfr bits associated with the resume interrupt. the ez-usb core asserts the resume signal when the ez-usb core senses a usb global resume, or when the ez-usb wakeup# pin is pulled low. the 8051 enables the resume inter- rupt by setting eicon.5. 9.3 wakeup interrupt eicon.5 eicon.4(rd) eicon.4(0) s r 8051 "resume" interrupt resume signal from ez-usb core
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-3 the 8051 reads the resume interrupt request bit in eicon.4, and clears the interrupt request by writing a zero to eicon.4. tb eicon.5 ; enable resume interrupt resume_isr: clr eicon.4 ; clear the 8051 w/u ; interrupt request reti
page 9-4 chapter 9. ez-usb interrupts ez-usb trm v1.9 figure 9-2 shows the 21 usb requests that share the 8051 usb (int2) interrupt. the bot- tom irq, ep7-out, is expanded in the diagram to show the logic associated with each usb interrupt request. vector 05, not shown in the diagram, exists only in the an2122/ an2126, and is described later in this chapter. figure 9-2. usb interrupts 9.4 usb signaling interrupts 8051 ez-usb ep0-in ep0-out ep1-in ep1-out ep2-in ep2-out ep3-in ep3-out sutok sudav sof susp eie.0 exif.4(rd) exif.4(0) s r 8051 "usb" interrupt out07ien.7 in07irq.7(1) s r in07irq.7 (rd) ures ep4-in ep4-out ep5-in ep5-out ep6-in ep6-out ep7-in ep7-out 0 iv4 iv3 iv2 iv1 iv0 0 0 avec 00 01 02 03 04 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 interrupt request latch ibn int 05
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-5 referring to the logic inside the dotted lines, each usb interrupt source has an interrupt request latch. the ez-usb core sets an irq bit, and the 8051 clears an irq bit by writing a 1 to it. the output of each latch is anded with an ien (interrupt enable) bit and then ord with all the other usb interrupt request sources. the ez-usb core prioritizes the usb interrupts, and constructs an autovector, which appears in the avec register. the interrupt vector values iv[4..0] are shown to the left of the interrupt sources (shaded boxes). 00 is the highest priority, 15 is the lowest. if two usb interrupts occur simultaneously, the prioritization affects which one is first indicated in the avec register. if the 8051 has enabled autovectoring, the avec byte replaces byte 0x45 in 8051 program memory. this causes the usb interrupt automatically to vec- tor to different addresses for each usb interrupt source. this mechanism is explained in detail in section 9.10, "usb autovectors." due to the or gate in figure 9-2, any of the usb interrupt sources sets the 8051 usb interrupt request latch, whose state appears as an interrupt request in the 8051 sfr bit exif.4. the 8051 enables the usb interrupt by setting sfr bit eie.0. to clear the usb interrupt request the 8051 writes a zero to the exif.4 bit. note that this is the opposite of clearing any of the individual usb interrupt sources, which the 8051 does by writing a 1 to the irq bit. when a usb resource requires service (for example, a sof token arrives or an out token arrives on a bulk endpoint), two things happen. first, the corresponding interrupt request latch is set. second, a pulse is generated, ord with the other usb interrupt logic, and routed to the 8051 int2 input. the pulse is required because int2 is edge trig- gered. when the 8051 finishes servicing a usb interrupt, it clears the particular irq bit by writ- ing a 1 to it. if any other usb interrupts are pending, the act of clearing the irq causes the ez-usb core logic to generate another pulse for the highest-priority pending interrupt. if more that one is pending, they are serviced in the priority order shown in figure 9-2, starting with sudav (priority 00) as the highest priority, and ending with ep7-out (pri- ority 15) as the lowest. important it is important in any usb interrupt service routine (isr) to clear the 8051 int2 inter- rupt before clearing the particular usb interrupt request latch. this is because as soon as the usb interrupt is cleared, any pending usb interrupt will pulse the 8051 int2 input, and if the int2 interrupt request latch has not been previously cleared the pending interrupt will be lost.
page 9-6 chapter 9. ez-usb interrupts ez-usb trm v1.9 figure 9-3 illustrates a typical usb isr for endpoint 2-in. figure 9-3. the order of clearing interrupt requests is important usb_isr: push dps push dpl push dph push dpl1 push dph1 push acc ; mov a,exif ; first clear the usb (int2) interrupt request clr acc.4 mov exif,a ; note: exif reg is not 8051 bit-addressable ; mov dptr,#in07irq ; now clear the usb interrupt request mov a,#00000100b ; use in2 as example movx @dptr,a ; ; (perform interrupt routine stuff) ; pop acc pop dph1 pop dpl1 pop dph pop dpl pop dps ; reti
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-7 figure 9-4. ez-usb interrupt registers figure 9-4 shows the registers associated with the usb interrupts. each interrupt source has an enable (ien) and a request (irq) bit. the 8051 sets the ien bit to enable the inter- rupt. the usb core sets an irq bit high to request an interrupt, and the 8051 clears an irq bit by writing a 1 to it. in07irq endpoints 0-7 in interrupt requests 7fa9 b7 b6 b5 b4 b3 b2 b1 b0 in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir out07irq endpoints 0-7 out interrupt requests 7faa b7 b6 b5 b4 b3 b2 b1 b0 out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir usbirq usb interrupt request 7fab b7 b6 b5 b4 b3 b2 b1 b0 - - - usesir suspir sutokir sofir sudavir in07ien endpoints 0-7 in interrupt enables 7fac b7 b6 b5 b4 b3 b2 b1 b0 in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien out07ien endpoints 0-7 out interrupt enables 7fad b7 b6 b5 b4 b3 b2 b1 b0 out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien usbien usb interrupt enables 7fae b7 b6 b5 b4 b3 b2 b1 b0 - - - uresie suspie sutokie sofie sudavie
page 9-8 chapter 9. ez-usb interrupts ez-usb trm v1.9 the usbien and usbirq registers control the first five interrupts shown in figure 9-2. the in07ien and out07 registers control the remaining 16 usb interrupts, which corre- spond to the 16 bulk endpoints in0-in7 and out0-out7. the 21 usb interrupts are now described in detail. figure 9-5. sutok and sudav interrupts sutok and sudav are supplied to the 8051 by ez-usb control endpoint zero. the first portion of a usb control transfer is the setup stage shown in figure 9-5. (a full control transfer is the setup stage shown in figure 7-1.) when the ez-usb core decodes a setup packet, it asserts the sutok (setup token) interrupt request. after the ez-usb core has received the eight bytes error-free and copied them into eight internal registers at setupdat, it asserts the sudav interrupt request. the 8051 program responds to the sudav interrupt by reading the eight setup data bytes in order to decode the usb request (chapter 7, "ez-usb endpoint zero"). the sutok interrupt is provided to give advance warning that the eight register bytes at setupdat are about to be over-written. it is useful for debug and diagnostic purposes. 9.5 sutok, sudav interrupts d a t a 0 8bytes setup data c r c 1 6 data packet a c k h/s pkt s e t u p a d d r e n d p c r c 5 token packet setup stage sutok interrupt sudav interrupt
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-9 figure 9-6. a start of frame (sof) packet usb start of frame interrupt requests occur every millisecond. when the ez-usb core receives an sof packet, it copies the eleven-bit frame number (frno in figure 9-6) into the usbframeh and usbframel registers, and activates the sof interrupt request. the 8051 services all isochronous endpoint data as a result of the sof interrupt. if the ez-usb detects 3 ms of no bus activity, it activates the susp (suspend) interrupt request. a full description of suspend-resume signaling appears in chapter 11, "ez-usb power management." the usb signals a bus reset by driving both d+ and d- low for at least 10 ms. when the ez-usb core detects the onset of usb bus reset, it activates the ures interrupt request. the remaining 16 usb interrupt requests are indexed to the 16 ez-usb bulk endpoints. the ez-usb core activates a bulk interrupt request when the endpoint buffer requires ser- vice. for an out endpoint, the interrupt request signifies that out data has been sent from the host, validated by the ez-usb core, and is sitting in the endpoint buffer memory. for an in endpoint, the interrupt request signifies that the data previously loaded by the 8051 into the in endpoint buffer has been read and validated by the host, making the in endpoint buffer ready to accept new data. 9.6 sof interrupt 9.7 suspend interrupt 9.8 usb reset interrupt 9.9 bulk endpoint interrupts s o f f r n o c r c 5 token pkt
page 9-10 chapter 9. ez-usb interrupts ez-usb trm v1.9 the ez-usb core sets an endpoints interrupt request bit when the endpoints busy bit (in the endpoint cs register) goes low, indicating that the endpoint buffer is available to the 8051. for example, when endpoint 4-out receives a data packet, the busy bit in the out4cs register goes low, and out07irq.4 goes high, requesting the endpoint 4-out interrupt. the usb interrupt is shared by 21 interrupt sources. to save the code and processing time required to sort out which usb interrupt occurred, the ez-usb core provides a second level of interrupt vectoring, called autovectoring. when the 8051 takes a usb inter- rupt, it pushes the program counter onto its stack, and then executes a jump to address 43, where it expects to find a jump instruction to an interrupt service routine. the 8051 jump instruction is encoded as follows: if autovectoring is enabled (aven=1 in the usbbav register), the ez-usb core substi- tutes its avec byte for the byte at address 0x0045. therefore, if the programmer pre- loads the high byte (page) of a jump table address at location 0x0044, the core-inserted byte at 0x45 will automatically direct the jump to one of 21 addresses within the page. in the jump table, the programmer then puts a series of jump instructions to each particular isr. 9.10 usb autovectors table 9-2. 8051 jump instruction address op-code hex value 0043 jump 0x02 0044 addrh 0xhh 0045 addrl 0xll
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-11 a detailed example of a program that uses autovectoring is presented in section 6.14, "interrupt bulk transfer example." the coding steps are summarized here. to employ ez-usb autovectoring: 1. insert a jump instruction at 0x43 to a table of jump instructions to the various usb interrupt service routines. table 9-3. a typical usb jump table table offset instruction 00 jmp sudav_isr 04 jmp sof_isr 08 jmp sutok_isr 0c jmp suspend_isr 10 jmp usbreset_isr 14 jmp ibn_isr (2122/2126 only, otherwise nop) 18 jmp ep0in _isr 1c jmp ep0out_isr 20 jmp in1buf_isr 24 jmp ep1out_isr 28 jmp ep2in_isr 2c jmp ep2out_isr 30 jmp ep3in_isr 34 jmp ep3out_isr 38 jmp ep4in_isr 3c jmp ep4out_isr 40 jmp ep5in_isr 44 jmp ep5out_isr 48 jmp ep6in_isr 4c jmp ep6out_isr 50 jmp ep7in_isr 54 jmp ep7out_isr 9.11 autovector coding
page 9-12 chapter 9. ez-usb interrupts ez-usb trm v1.9 2. code the jump table with jump instructions to each individual usb interrupt ser- vice routine. this table has two important requirements, arising from the format of the avec byte (zero-based, with 2 lsbs set to 0): ? it must begin on a page boundary (address 0xnn00). ? the jump instructions must be four bytes apart. ? the interrupt service routines can be placed anywhere in memory. ? write initialization code to enable the usb interrupt (int2), and autovector- ing. figure 9-7. the autovector mechanism in action figure 9-7 illustrates an isr that services endpoint 2-out. when endpoint 2-out requires service, the ez-usb core activates the usb interrupt request, vectoring the 8051 to location 0x43. the jump instruction at this location, which was originally coded as ljmp 04- 00 becomes ljmp 04- 2c due to the ez-usb core substituting 2c as the autovector byte for endpoint 2-out (table 9-3). the 8051 jumps to 042c, where it exe- cutes the jump instruction to the endpoint 2-out isr shown in this example at address 0119. once the 8051 takes the vector at 0043, initiation of the endpoint-specific isr takes only eight 8051 cycles. ep2out_isr: usb_jmp_table: ljmp 04 (00)2c 0043 0044 0045 2c avec usb core ljmp ep2out_isr 01 19 042c 042d 042e 0400 0119 8051 usb interrupt vector
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-13 figure 9-8. i 2 c interrupt enable bits and registers chapter 4, "ez-usb input/output" describes the 8051 interface to the ez-usb i 2 c con- troller. the 8051 uses two registers, i2cs (i 2 c control and status) and i2dat (i 2 c data) to transfer data over the i 2 c bus. the ez-usb core signals completion of a byte transfer by setting the done bit (i2cs.0) high, which also sets an i 2 c interrupt request latch (figure 9-8). this interrupt request is routed to the 8051 int3 interrupt. the 8051 enables the i 2 c interrupt by setting eie.1=1. the 8051 determines the state of the interrupt request flag by reading exif.5, and resets the int3 interrupt request by writ- ing a zero to exif.5. any 8051 read or write to the i2dat or i2cs register automatically clears the i 2 c interrupt request. the ez-usb family responds to an in token from the host by loading an in endpoint buffer and then arming the endpoint by loading a byte count for the endpoint. after the host successfully receives the in data, the 8051 receives an ep-in interrupt, signifying that the in endpoint buffer is once again ready to accept data. 9.12 i 2 c interrupt 9.13 in bulk nak interrupt - (an2122/an2126 only) eie.1 exif.5(rd) exif.5(0) s r 8051 i 2 c interrupt (int3) i 2 c interrupt request done s r rd or wr i2dat register i2cs i2dat start stop lastrd id1 id0 berr ack d7 d6 d5 d4 d3 d2 d1 d0 done ez-usb 8051
page 9-14 chapter 9. ez-usb interrupts ez-usb trm v1.9 in some situations, the host may send in tokens before the 8051 has loaded and armed an in endpoint. to alert the 8051 that an in endpoint is being pinged , the an2122/26 add a set of interrupts, one per in endpoint, that indicate that an in endpoint just sent a nak to the host. this happens when the host sends an in token and the in endpoint does not have data (yet) for the host. the new interrupt is called ibn, for in bulk nak. its int2 autovector is 05, which was previously reserved in the ez-usb family. the ibn interrupt requests and enables are controlled by two new registers. note that because the ibn interrupt exists only in the an2122/an2126, which has 6 bulk in end- points, there are irq and ien bits endpoints in0 through in6. figure 9-9. in bulk nak interrupt request register figure 9-10. in bulk nak interrupt enable register each of the individual in endpoints may be enabled for an ibn interrupt using the ibnen register. the 8051 sets an interrupt enable bit to 1 to enable the corresponding interrupt. the isr tests the ibnirq bits to determine which endpoint or endpoints generated the interrupt request. as with all other ez-usb interrupt requests, the 8051 clears an ibnirq bit by writing a 1 to it. ibnirq in bulk nak interrupt requests 7fb0 b7 b6 b5 b4 b3 b2 b1 b0 - ep6in ep5in ep4in ep3in ep2in ep1in ep0in r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x ibnen in bulk nak interrupt enables 7fb1 b7 b6 b5 b4 b3 b2 b1 b0 - ep6in ep5in ep4in ep3in ep2in ep1in ep0in r/w r/w r/w r/w r/w r/w r/w r/w x 0 0 0 0 0 0 0
ez-usb trm v1.9 chapter 9. ez-usb interrupts page 9-15 figure 9-11. i 2 cmoderegister the i 2 c interrupt includes one additional interrupt source in the an2122/an2126, a 1-0 transition of the stop bit. to enable this interrupt, set the stopie bit in the i2cmode register. the 8051 determines the interrupt source by checking the done and stop bits in the i2cs register. figure 9-12. i 2 c control and status register figure 9-13. i 2 cdata 9.14 i 2 c stop complete interrupt - (an2122/an2126 only) i2cmode i 2 c mode 7fa7 b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 0 0 stopie 0 r r r r r r r/w r 0 0 0 0 0 0 0 0 i2cs i 2 c control and status 7fa5 b7 b6 b5 b4 b3 b2 b1 b0 start stop lastrd id1 id0 berr ack done r/w r/w r/w r r r r r 0 0 0 x x 0 0 0 i2dat i 2 c data 7fa6 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
page 9-16 chapter 9. ez-usb interrupts ez-usb trm v1.9 the two registers that the 8051 uses to control i 2 c transfers are shown above. in the ez- usb family, an i 2 c interrupt request occurs on int3 whenever the done bit (i2cs.0) makes a 0-to-1 transition. this interrupt signals the 8051 that the i 2 c controller is ready for another command. the 8051 concludes i 2 c transfers by setting the stop bit (i2cs.6). when the stop con- dition has been sent over the i 2 c bus, the i 2 c controller resets i2cs.6 to zero. during the time the i 2 c controller is generating the stop condition, it ignores accesses to the i2cs and i2dat registers. the 8051 code should therefore check the stop bit for zero before writ- ing new data to i2cs or i2dat. in the ez-usb family, it does this by polling the i2cs.6 bit.
ez-usb trm v1.9 chapter 10. ez-usb resets page 10-1 10 ez-usb resets the ez-usb chip has three resets: ? a power-on reset (por), which turns on the ez-usb chip in a known state. ? an 8051 reset, controlled by the ez-usb core. ? a usb bus reset, sent by the host to reset a device. this chapter describes the effects of these three resets. figure 10-1. ez-usb resets when power is first applied to the ez-usb chip, the external r-c circuit holds the ez- usb core in reset until the on-chip pll stabilizes. the clk24 pin is active as soon as power is applied. the 8051 may clear an ez-usb control bit, clk24oe, to inhibit the clk24 output pin for emi-sensitive applications that do not need this signal. external logic can force a chip reset by pulling the reset pin hi. the reset pin is normally 10.1 introduction 10.2 ez-usb power-on reset (por) reset res ez-usb core 8051 res cpucs.0 (1 at pwr on) oscillator xin xout pll 2 12 mhz clk24 24 mhz 48 mhz usb bus reset vcc
page 10-2 chapter 10. ez-usb resets ez-usb trm v1.9 connected to vcc through a 1 m f capacitor and to gnd through a 10-k resistor (figure 10-1). the oscillator and pll are unaffected by the state of the reset pin. the clk24 signal is active while reset = hi. when reset returns lo, the activity on the clk24 pin depends on whether or not the ez-usb chip is in suspend state. if in sus- pend, clk24 stops. resumption of usb bus activity or asserting the wakeup# pin lo re-starts the clk24 signal. power-on default values for all ez-usb register bits are shown in chapter 12, "ez-usb registers." table 10-1 summarizes reset states that affect usb device operation. note that the term power-on reset refers to a reset initiated by application of power, or by assertion of the reset pin. * when the 8051 is released from reset, the ez-usb automatically arms the bulk out endpoints by setting their cs registers to 000000010b. table 10-1. ez-usb states after power-on reset (por) item register default value comment 1 endpoint data xxxxxxxx 2 byte counts xxxxxxxx 3 cpucs rrrr0011 rrrr=rev number, b1 =clk24oe, b0=8051res 4 port configs 00000000 io, not alternate functions 5 port registers xxxxxxxx 6 port oes 00000000 inputs 7 interrupt enables 00000000 disabled 8 interrupt reqs 00000000 cleared 9 bulk in c/s 00000000 bulk in endpoints not busy (unarmed) 10 bulk out c/s* 00000000 bulk out endpoints not busy (unarmed) 11 toggle bits 00000000 data toggles = 0 12 usbcs 00000100 renum=0, discoe=1 (discon pin drives) 13 fnaddr 00000000 usb function address 14 in07val 01010111 ep0,1,2,4,6 in valid 15 out07val 01010101 ep0,2,4,6 out valid 16 inisoval 00000111 ep8,9,10 in valid 17 outisoval 00000111 ep8,910out valid 18 usbpair 0x000000 isosend0 (b7) = 0, no pairing 19 usbbav 00000000 break condition cleared, no autovector 20 configuration 0 internal ez-usb core value 21 alternate setting 0 internal ez-usb core value
ez-usb trm v1.9 chapter 10. ez-usb resets page 10-3 from table 10-1, at power-on: ? endpoint data buffers and byte counts are un-initialized (1,2). ? the 8051 is held in reset, and the clk24 pin is enabled (3). ? all port pins are configured as input ports (4-6). ? usb interrupts are disabled, and usb interrupt requests are cleared (7-8). ? bulk in and out endpoints are unarmed, and their stall bits are cleared (9). the ez-usb core will nak in or out tokens while the 8051 is reset. out end- points are enabled when the 8051 is released from reset. ? endpoint toggle bits are cleared (11). ? the renum bit is cleared. this means that the ez-usb core, and not the 8051, initially responds to usb device requests (12). ? the usb function address register is set to zero (13). ? the endpoint valid bits are set to match the endpoints used by the default usb device (14-17). ? endpoint pairing is disabled. also, isosend0=0, meaning that if an isochronous endpoint receives an in token without being loaded by the 8051 in the previous frame, the ez-usb core does not generate any response (18). ? the breakpoint condition is cleared, and autovectoring is turned off (19). ? configuration zero, alternate setting zero is in effect (20-21). the ez-usb register bit cpucs.0 resets the 8051. this bit is hi at power-on, initially holding the 8051 in reset. there are three ways to release the 8051 from reset: ? by the host, as the final step of a ram download. ? automatically, as part of an eeprom load. ? automatically, when external rom is used (ea=1). 10.3 releasing the 8051 reset
page 10-4 chapter 10. ez-usb resets ez-usb trm v1.9 10.3.1 ram download once enumerated, the host can download code into the ez-usb ram using the firm- ware load vendor request (chapter 7, "ez-usb endpoint zero"). the last packet loaded writes 0 to the cpucs register, which clears the 8051 reset bit. 10.3.2 eeprom load chapter 5 describes the eeprom boot loads in detail. briefly, at power-on, the ez-usb core checks for the presence of an eeprom on its i 2 c bus. if found, it reads the first eeprom byte. if it reads 0xb2 as the first byte, the ez-usb core downloads 8051 code from the eeprom into internal ram. the last byte of a b2 load writes 0x00 to the cpucs register (at 0x7f92), which releases the 8051 from reset. 10.3.3 external rom ez-usb systems can use external program memory containing 8051 code and usb device descriptors, which include the vid/did/pid bytes. because these systems do no require and i 2 c eeprom to supply the vid/did/pid, the ez-usb core automatically releases 8051 reset when: 1. ea=1 (external code memory), and 2. no b0/b2 eeprom is detected on the i 2 c bus. the ez-usb core also sets the renum bit to 1, giving usb control to the 8051. once the 8051 is running, the usb host may reset the 8051 by downloading the value 0x01 to the cpucs register. the host might do this in preparation for loading code over- lays, effectively magnifying the size of the internal ez-usb ram. for such applications it is important to know the state of the ez-usb chip during and after an 8051 reset. in this note the other bit in the cpucs register, clk24oe, is writable only by the 8051, so the host writing a zero byte to this register does not turn off the clk24 signal. 10.4 8051 reset effects
ez-usb trm v1.9 chapter 10. ez-usb resets page 10-5 section, this particular reset is called an 8051 reset, and should not be confused with the por described in section 10.2, "ez-usb power-on reset (por)." this discussion applies only to the condition where the ez-usb chip is powered, and the 8051 is reset by the host setting the cpucs register to 0. the basic usb device configuration remains intact through an 8051 reset. valid end- points remain valid, the usb function address remains the same, and the io ports retain their configurations and values. stalled endpoints remain stalled, and data toggles dont change. the only effects of an 8051 reset are as follows: ? usb interrupts are disabled, but pending interrupt requests remain pending. ? during the 8051 reset, all bulk endpoints are unarmed, causing the ez-usb core to nak and in or out tokens. ? after the 8051 reset is removed, the out bulk endpoints are automatically armed. out endpoints are thus ready to accept one out packet before 8051 intervention is required. ? the breakpoint condition is cleared. the renum bit is not affected by an 8051 reset. when the 8051 comes out of reset, the pending interrupts are kept pending, but disabled (1). this gives the firmware writer the choice of acting on pre-8051-reset usb events, or ignoring them by clearing the pending interrupt(s). during the 8051 reset time, the ez-usb core holds off any usb traffic by naking in and out tokens (2). the ez-usb core automatically arms the out endpoints when the 8051 exits the reset state (3). usbbav.3, the breakpoint break bit, is cleared (4). the other bits in the usbbav reg- ister are unaffected. the host signals a usb bus reset by driving an se0 state (both d+ and d- data lines low) for a minimum of 10 ms. the ez-usb core senses this condition, requests the 8051 usb interrupt (int2), and supplies the interrupt vector for a usb reset. a usb reset affects the ez-usb resources as shown in table 10-2. 10.5 usb bus reset
page 10-6 chapter 10. ez-usb resets ez-usb trm v1.9 a usb bus reset leaves most ez-usb resources unchanged. from table 10-2, after usb bus reset: ?theez-usbcore unarms all bulk in endpoints (9). data loaded by the 8051 into an in endpoint buffer remains there, and the 8051 firmware can either re-send it by loading the endpoint byte count register to re-arm the transfer, or send new data by re-loading the in buffer before re-arming the endpoint. ? bulk out endpoints retain their busy states (10). data sent by the host to an out endpoint buffer remains in the buffer, and the 8051 firmware can either read the data or reject it as stale simply by not reading it. in either case, the 8051 loads a dummy value to the endpoint byte count register to re-arm out transfers. ? toggle bits are cleared (11). ? the device address is reset to zero (13). table 10-2. ez-usb states after a usb bus reset item register default value comment 1 endpt data uuuuuuuu u = unchanged 2 byte counts uuuuuuuu 3 cpucs uuuuuuuu 4 port configs uuuuuuuu 5 port registers uuuuuuuu 6 port oes uuuuuuuu 7 interrupt enables uuuuuuuu 8 interrupt reqs uuuuuuuu 9 bulk in c/s 00000000 unarm 10 bulk out c/s uuuuuuuu retain armed/unarmed state 11 toggle bits 00000000 12 usbcs uuuuuuuu renum bit unchanged 13 fnaddr 00000000 usb function address 14 in07val uuuuuuuu 15 out07val uuuuuuuu 16 inisoval uuuuuuuu 17 outisoval uuuuuuuu 18 usbpair uuuuuuuu 19 configuration 0 20 alternate setting 0
ez-usb trm v1.9 chapter 10. ez-usb resets page 10-7 note from item 12 that the renum bit is unchanged after a usb bus reset. therefore, if a device has renumerated ? and loaded a new personality, it retains the new personality through a usb bus reset. although not strictly a reset, when the ez-usb simulates a disconnect-reconnect in order to renumerate ? , there are effects on the ez-usb core: ? bulk in endpoints are unarmed, and bulk out endpoints are armed (9-10). ? endpoint stall bits are cleared (9-10). ? data toggles are reset (11). 10.6 ez-usb disconnect table 10-3. effects of an ez-usb disconnect and re-connect item register default value comment 1 endpt data uuuuuuuu u = unchanged 2 byte counts uuuuuuuu 3 cpucs uuuuuuuu 4 port configs uuuuuuuu 5 port registers uuuuuuuu 6 port oes uuuuuuuu 7 interrupt enables uuuuuuuu 8 interrupt reqs uuuuuuuu 9 bulk in c/s 00000000 unarm, clear stall bit 10 bulk out c/s 00000000 arm, clear stall bit 11 toggle bits 00000000 reset 12 usbcs uuuuuuuu renum bit unchanged 13 fnaddr 00000000 usb function address 14 in07val uuuuuuuu 15 out07val uuuuuuuu 16 inisoval uuuuuuuu 17 outisoval uuuuuuuu 18 usbpair uuuuuuuu 19 configuration 0 20 alternate setting 0
page 10-8 chapter 10. ez-usb resets ez-usb trm v1.9 ? the function address is reset to zero (13). ? the configuration is reset to zero (19). ? alternate settings are reset to zero (20). table 10-4 summarizes the effects of the four ez-usb resets. 10.7 reset summary table 10-4. effects of various ez-usb resets (u means unaffected) resource reset pin usb bus reset disconnect 8051 reset 8051 reset reset u u n/a ep0-7 in eps unarm unarm unarm unarm ep0-7 out eps unarm u arm unarm/arm breakpoint reset u u reset stall bits reset u reset u interrupt enables reset u u reset interrupt reqs reset u u u clk24 run u u u data toggles reset reset reset u function address reset reset reset u configuration 0 0 0 u renum 0 u u u note the i 2 c controller is not reset for any of the conditions laid out in table 10-4. only the ez-usb reset pin resets it.
ez-usb trm v1.9 chapter 11. ez-usb power management page 11-1 11 ez-usb power management the usb host can suspend a device to put it into a power-down mode. when the usb signals a suspend operation, the ez-usb chip goes through a sequence of steps to allow the 8051 to first turn off external power-consuming subsystems, and then enter an ultra-low-power mode by turning off its oscillator. once suspended, the ez-usb chip is awakened either by resumption of usb bus activity, or by assertion of its wakeup# pin. this chapter describes the suspend-resume mechanism. figure 11-1. suspend-resume control figure 11-1 illustrates the ez-usb logic that implements usb suspend and resume. these operations are explained in the next sections. 11.1 introduction pll oscillator div by 2 8051 48 mhz clk24 12 mhz start usb resume wakeup pin pcon.0 stop usb "suspend" interrupt no usb activity for 3 msec. resume int signal resume (usbcs.0) restart delay
page 11-2 chapter 11. ez-usb power management ez-usb trm v1.9 figure 11-2. ez-usb suspend sequence a usb device recognizes suspend as 3 ms of a bus idle (j) state. the ez-usb core alerts the 8051 by asserting the usb (int2) interrupt and the suspend interrupt vector. this gives the 8051 code a chance to perform power suspend interrupt vector. this gives the 8051 code a chance to perform power conservation housekeeping before shut- ting down the oscillator. 11.2 suspend pll oscillator div by 2 8051 48 mhz clk24 12 mhz stop usb "suspend" interrupt no usb activity for 3 msec. int2 pcon.0
ez-usb trm v1.9 chapter 11. ez-usb power management page 11-3 the 8051 code responds to the suspend interrupt by taking the following steps: 1. performs any necessary housekeeping such as shutting off external power-con- suming devices. 2. sets bit 0 of the pcon sfr (special function register). this has two effects: ? the 8051 enters its idle mode, which is exited by any interrupt. ? the 8051 sends an internal signal to the ez-usb core which causes it to turn off the oscillator and pll. these actions put the ez-usb chip into a low-power mode, as required by the usb spec- ification. figure 11-3. ez-usb resume sequence 11.3 resume pll oscillator div by 2 8051 48 mhz clk24 12 mhz start usb resume wakeup# pin resume int signal resume (usbcs.0) restart delay
page 11-4 chapter 11. ez-usb power management ez-usb trm v1.9 the ez-usb oscillator re-starts when: ? usb bus activity resumes (shown as usb resume in figure 11-3), or ? external logic asserts the ez-usb wakeup# pin low. after an oscillator stabilization time, the ez-usb core asserts the 8051 resume interrupt (figure 9-1). this causes the 8051 to exit its idle mode. the resume interrupt is the high- est priority 8051 interrupt. it is always enabled, unaffected by the ea bit. the resume isr clears the interrupt request flag, and executes an reti (return from inter- rupt) instruction. this causes the 8051 to continue program execution at the instruction following the one that set pcon.0 to initiate the suspend operation. figure 11-4. usb control and status register two bits in the usbcs register are used for remote wakeup, wakesrc and sigr- sume. after exiting the idle state, the 8051 reads the wakesrc bit in the usbcs register to discover how the wakeup was initiated. wakesrc=1 indicates assertion of the wakeup# pin, and wakesrc=0 indicates a resumption of usb bus activity. the 8051 clears the wakesrc bit by writing a 1 to it. about the resume interrupt the 8051 enters the idle mode when pcon.0 is set to 1. although the 8051 exits its idle state when any interrupt occurs, the ez-usb logic supports only the resume inter- rupt for the usb resume operation. this is because the ez-usb core asserts this partic- ular interrupt after restarting the 8051 clock. 11.4 remote wakeup usbcs usb control and status 7fd6 b7 b6 b5 b4 b3 b2 b1 b0 wa k e s r c - - - discon discoe renum sigrsume
ez-usb trm v1.9 chapter 11. ez-usb power management page 11-5 when a usb device is suspended, the hub driver is tri-stated, and the bus pullup and pull- down resistors cause the bus to assume the j, or idle state. a suspended device signals a remote wakeup by asserting the k state for 10-15 ms. the 8051 controls this using the sigrsume bit in the usbcs register. if the 8051 finds wakesrc=1 after exiting the idle mode, it drives the k state for 10- 15 ms to signal the usb remote wakeup. it does this by setting sigrsume=1, waiting 10-15 ms, and then setting sigrsume=0. when sigrsume=0, the ez-usb bus buffer reverts to normal operation. the resume routine should also write a 1 to the wakesrc bit to clear it. the usb default device does not support remote wakeup. this fact is reported at enu- meration time in byte 7 of the built-in configuration descriptor (table 5-10). note if your design does not use remote wakeup, tie the wakeup# pin high. holding the wakeup# pin low inhibits the ez-usb chip from suspending. jandkstates the usb specification uses differential data signals d+ and d-. instead of defining a logical 1 and 0, it defines the j and k states. for a high speed device, the j state means (d+ > d-). remote wakeup: the big picture additional factors besides the ez-usb suspend-resume mechanism described in this section determine whether remote wakeup is possible. these are: 1. the device must report that it is capable of signaling a remote wakeup in the bat- tributes field of its configuration descriptor. see table 5-10 for an example of this descriptor. 2. the host must issue a set_feature/device request with the feature selector field set to 0x01 to enable remote wakeup. see table 7-6 for the detailed request.
page 11-6 chapter 11. ez-usb power management ez-usb trm v1.9
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-1 12 ez-usb registers this section describes the ez-usb registers in the order they appear in the ez-usb mem- ory map. the registers are named according to the following conventions. most registers deal with endpoints. the general register format is dddnfff, where: ddd is endpoint direction, in or out with respect to the usb host. n is the endpoint number, where: ? 07 refers to endpoints 0-7 as a group. ? 0-7 refers to each individual bulk/interrupt/control endpoint. ? iso indicates isochronous endpoints as a group. fff is the function, where: ? cs is a control and status register ? irq is an interrupt request bit ? ie is an interrupt enable bit ? bc, bcl, and bch are byte count registers. bc is used for single byte counts, and bcl/h are used as the low and high bytes of 16-bit byte counts. ? data is a single-register access to a fifo. ? buf is the start address of a buffer. examples: ? in7bc is the endpoint 7 in byte count. ? out07irq is the register containing interrupt request bits for out endpoints 0-7. ? inisoval contains valid bits for the isochronous in endpoints (ep8in-ep15in). 12.1 introduction
page 12-2 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-1. register description format figure 12-1 illustrates the register description format used in this chapter. ? the top line shows the register name, functional description, and address in the ez-usb memory. ? the second line shows the bit position in the register. ? the third line shows the name of each bit in the register. ? the fourth line shows 8051 accessibility: r(ead), w(rite), or r/w. ? the fifth line shows the default value. these values apply after a power-on-reset (por). other conventions usb indicates a global (not endpoint-specific) usb function. addr is an address. val means valid. frame is a frame count. ptr is an address pointer. register name register function address b7 b6 b5 b4 b3 b2 b1 b0 bitname bitname bitname bitname bitname bitname bitname bitname r, w access r, w access r, w access r, w access r, w access r, w access r, w access r, w access default val default val default val default val default val default val default val default val
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-3 * see table 12-1 for individual endpoint buffer addresses. figure 12-2. bulk data buffers sixteen 64-byte bulk data buffers appear at 0x1b40 and 0x7b40 in the 8k version of ez- usb, and only at 0x7b40 in the 32k version of ez-usb. the endpoints are ordered to permit the reuse of the buffer space as contiguous ram when the higher numbered end- points are not used. these registers default to unknown states. 12.2 bulk data buffers innbuf,outnbuf endpoint 0-7 in/out data buffers 1b40-1f3f* b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x table 12-1. bulk endpoint buffer memory addresses address address name size 1f00-1f3f 7f00-7f3f in0buf 64 1ec0-1eff 7ec0-7eff out0buf 64 1e80-1ebf 7e80-7ebf in1buf 64 1e40-1e7f 7e40-7e7f out1buf 64 1e00-1e3f 7e00-7e3f in2buf 64 1dc0-1dff 7dc0-7dff out2buf 64 1d80-1dbf 7d80-7dbf in3buf 64 1d40-1d7f 7d40-7d7f out3buf 64 1d00-1d3f 7d00-7d3f in4buf 64 1cc0-1cff 7cc0-7cff out4buf 64 1c80-1cbf 7c80-7cbf in5buf 64 1c40-1c7f 7c40-7c7f out5buf 64 1c00-1c3f 7c00-7c3f in6buf 64 1bc0-1bff 7bc0-7bff out6buf 64 1b80-1bbf 7b80-7bbf in7buf 64 1b40-1b7f 7b40-7b7f out7buf 64
page 12-4 chapter 12. ez-usb registers ez-usb trm v1.9 * see table 12-2 for individual endpoint buffer addresses. figure 12-3. isochronous data fifos 12.3 isochronous data fifos outndata ep8out-ep15out fifo registers 7f60-7f67* b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r r r r r r r r x x x x x x x x inndata ep8in-ep15in fifo registers 7f68-7f6f* b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 w w w w w w w w x x x x x x x x table 12-2. isochronous endpoint fifo register addresses address isochronous data name 7f60 endpoint 8 out data out8data 7f61 endpoint 9 out data out9data 7f62 endpoint 10 out data out10data 7f63 endpoint 11 out data out11data 7f64 endpoint 12 out data out12data 7f65 endpoint 13 out data out13data 7f66 endpoint 14 out data out14data 7f67 endpoint 15 out data out15data 7f68 endpoint 8 in data in8data 7f69 endpoint 9 in data in9data 7f6a endpoint 10 in data in10data 7f6b endpoint 11 in data in11data 7f6c endpoint 12 in data in12data 7f6d endpoint 13 in data in13data 7f6e endpoint 14 in data in14data 7f6f endpoint 15 in data in15data
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-5 sixteen addressable data registers hold data from the eight isochronous in endpoints and the eight isochronous out endpoints. reading a data register reads a receive fifo byte (usb out data); writing a data register loads a transmit fifo byte (usb in data).
page 12-6 chapter 12. ez-usb registers ez-usb trm v1.9 * see table 12-3 for individual endpoint buffer addresses. figure 12-4. isochronous byte counts 12.4 isochronous byte counts outnbch out(8-15) byte count high 7f70-7f7f* b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 0 0 bc9 bc8 r r r r r r r r x x x x x x x x innbcl out(8-15) byte count low 7f70-7f7f* b7 b6 b5 b4 b3 b2 b1 b0 bc7 bc6 bc5 bc4 bc3 bc2 bc1 bc0 r r r r r r r r x x x x x x x x table 12-3. isochronous endpoint byte count register addresses address isochronous data name 7f70 endpoint 8 byte count high out8bch 7f71 endpoint 8 byte count low out8bcl 7f72 endpoint 9 byte count high out9bch 7f73 endpoint 9 byte count low out9bcl 7f74 endpoint 10 byte count high out10bch 7f75 endpoint 10 byte count low out10bcl 7f76 endpoint 11 byte count high out11bch 7f77 endpoint 11 byte count low out11bcl 7f78 endpoint 12 byte count high out12bch 7f79 endpoint 12 byte count low out12bcl 7f7a endpoint 13 byte count high out13bch 7f7b endpoint 13 byte count low out13bcl 7f7c endpoint 14 byte count high out14bch 7f7d endpoint 14 byte count low out14bcl 7f7e endpoint 15 byte count high out15bch 7f7f endpoint 15 byte count low out15bcl
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-7 the ez-usb core uses the byte count registers to report isochronous data payload sizes for out data transferred from the host to the usb core. ten bits of byte count data allow payload sizes up to 1,023 bytes. a byte count of zero is valid, meaning that the host sent no isochronous data during the previous frame. the default values of these registers are unknown. byte counts are valid only for out endpoints. the byte counts indicate the number of bytes remaining in the endpoints receive fifo. every time the 8051 reads a byte from the isodata register, the byte count decrements by one. to read usb out data, the 8051 first reads byte count registers outnbcl and outn- bch to determine how many bytes to transfer out of the out fifo. (the 8051 can also quickly test iso output endpoints for zero byte counts using the zbcout register.) then, the cpu reads that number of bytes from the isodata register. separate byte counts are maintained for each endpoint, so the cpu can read the fifos in a discontinu- ous manner. for example, if ep8 indicates a byte count of 100, and ep9 indicates a byte count of 50, the cpu could read 50 bytes from ep8, then read 10 bytes from ep9, and resume reading ep8. at this moment the byte count for ep8 would read 50. there are no byte count registers for the in endpoints. the usb core automatically tracks the number of bytes loaded by the 8051. if the 8051 does not load an in isochronous endpoint fifo during a 1-ms frame, and the host requests data from that endpoint during the next frame (in token), the usb core responds according to the setting of the isosend0 bit (usbpair.7). if isosend0=1, the core returns a zero-length data packet in response to the host in token. if isos- end=0, the core does not respond to the in token. it is the responsibility of the 8051 programmer to ensure that the number of bytes written to the in fifo does not exceed the maximum packet size as reported during enumeration.
page 12-8 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-5. cpu control and status register this register enables the clk24 output and permits the host to reset the 8051 using a firmware download. bit 7-4: rv[3..0] silicon revision these register bits define the silicon revision. consult individual cypress semiconductor data sheets for values. bit 1: clk24oe output enable - clk24 pin when this bit is set to 1, the internal 24-mhz clock is connected to the ez-usb clk24 pin. when this bit is 0, the clk24 pin drives hi. this bit can be written by the 8051 only. bit 0: 8051res 8051 reset the usb host writes 1 to this bit to reset the 8051, and 0 to run the 8051. only the usb host can write this bit. 12.5 cpu registers cpucs cpu control and status 7f92 b7 b6 b5 b4 b3 b2 b1 b0 rv3 rv2 rv1 rv0 0 0 clk24oe 8051res r r r r r r r/w r rv3 rv2 rv1 rv0 0 0 1 1
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-9 figure 12-6. io port configuration registers these three registers control the three io ports on the ez-usb chip. they select between io ports and various alternate functions. they are read/write by the 8051. when portncfg=0, the port pin functions as io, using the out, pins, and oe control bits. data written to an outn registers appears on an io port pin if the corresponding output enable bit (oen) is hi. when portncfg=1, the pin assumes the alternate function shown in table 12-4 on the following page. 12.6 port configuration portacfg io port a configuration 7f93 b7 b6 b5 b4 b3 b2 b1 b0 rxd1out rxd0out frd fwr cs oe t1out t0out r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 portbcfg io port b configuration 7f94 b7 b6 b5 b4 b3 b2 b1 b0 t2out int6 int5 int4 txd1 rxd1 t2ex t2 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 portccfg io port c configuration 7f95 b7 b6 b5 b4 b3 b2 b1 b0 rd wr t1 t0 int1 int0 txd0 rxd0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
page 12-10 chapter 12. ez-usb registers ez-usb trm v1.9 table 12-4. io pin alternate functions i/o name alternate functions pa0 t0out timer 0 output pa1 t1out timer 1 output pa2 oe# external memory output enable pa3 cs# external memory chip select pa4 fwr# fast access write strobe pa5 frd# fast access read strobe pa6 rxd0out mode 0: uart0 synchronous data output pa7 rxd1out mode 0: uart1 synchronous data output pb0 t2 timer/counter 2 clock input pb1 t2ex timer/counter 2 capture/reload input pb2 rxd1 serial port 1 input pb3 txd1 mode 0: clock output modes 1-3: serial port 1 data output pb4 int4 int4 interrupt request pb5 int5# int5 interrupt request pb6 int6 int6 interrupt request pb7 t2out timer/counter 2 overflow indication pc0 rxd0 serial port 0 input pc1 txd0 mode 0: clock output modes 1-3: serial port 0 data output pc2 int0# int0 interrupt request pc3 int1# int1 interrupt request pc4 t0 timer/counter 0 external input pc5 t1 timer/counter 1 external input pc6 wr# external memory write strobe pc7 rd# external memory read strobe
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-11 figure 12-7. output port configuration registers the outn registers provide the data that drives the port pin when oe=1 and the port- ncfg pin is 0. if the port pin is selected a an input (oe=0), the value stored in the corre- sponding outn bit is stored in an output latch but not used. 12.7 input-output port registers outa port a outputs 7f96 b7 b6 b5 b4 b3 b2 b1 b0 outa7 outa6 outa5 outa4 outa3 outa2 outa1 outa0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 outb port b outputs 7f97 b7 b6 b5 b4 b3 b2 b1 b0 outb7 outb6 outb5 outb4 outb3 outb2 outb1 outb0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 outc port c outputs 7f98 b7 b6 b5 b4 b3 b2 b1 b0 outc7 outc6 outc5 outc4 outc3 outc2 outc1 outc0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
page 12-12 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-8. pinsn registers the pinsn registers contain the current value of the port pins, whether they are selected as io ports or alternate functions. pinsa port a pins 7f99 b7 b6 b5 b4 b3 b2 b1 b0 pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 r r r r r r r r x x x x x x x x pinsb port b pins 7f9a b7 b6 b5 b4 b3 b2 b1 b0 pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 r r r r r r r r x x x x x x x x outc port c pins 7f98 b7 b6 b5 b4 b3 b2 b1 b0 pinc7 pinc6 pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 r r r r r r r r x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-13 figure 12-9. output enable registers the oe registers control the output enables on the tri-state drivers connected to the port pins. when these bits are 1, the port is an output, unless the corresponding portncfg bit is set to a 1. oea port a output enable 7f9c b7 b6 b5 b4 b3 b2 b1 b0 oea7 oea6 oea5 oea4 oea3 oea2 oea1 oea0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x oeb port b output enable 7f9d b7 b6 b5 b4 b3 b2 b1 b0 oeb7 oeb6 oeb5 oeb4 oeb3 oeb2 oeb1 oeb0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x oec port c output enable 7f9e b7 b6 b5 b4 b3 b2 b1 b0 oec7 oec6 oec5 oec4 oec3 oec2 oec1 oec0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
page 12-14 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-10. 230-kbaud uart operation register bit 1: uart1 universal 115/230 kbaud operation for uart1 bit 0: uart0 universal 115/230 kbaud operation for uart0 these bits, when set to 1, connect an internal 3.69-mhz clock to uart0 and/or uart1. the uarts divide this frequency by 16, giving a 230-khz baud clock if the cor- responding smod bit is set, or 115 baud clock if the corresponding smod bit is clear. (note: smod0 is bit 7 or sfr 0x87, smod1 is bit 7 or sfr 0xd8). when the uart0 or uart1 bit is clear, the normal uart clock sources are used. figure 12-11. isochronous out endpoint error register the isoerr bits are updated at every sof. they indicate that a crc error was received on a data packet for the current frame. the isoerr bit status refers to the usb data received in the previous frame, and which is currently in the endpoints out fifo. if the isoerr bit = 1, indicating a bad crc check, the data is still available in the outndata register. 12.8 230-kbaud uart operation - an2122, an2126 uart230 230-kbaud uart control 7f9f b7 b6 b5 b4 b3 b2 b1 b0 - - - - - - uart1 uart0 r r r r r r r/w r/w 0 0 0 0 0 0 0 0 12.9 isochronous control/status registers isoerr isochronous out ep error 7fa0 b7 b6 b5 b4 b3 b2 b1 b0 iso15err iso14err iso13err iso12err iso11err iso10err iso9err iso8err r r r r r r r r x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-15 figure 12-12. isochronous control register bit 3: ppstat ping-pong status this bit indicates the isochronous buffer currently in use by the ez-usb core. it is used only for diagnostic purposes. bits 2,1: mbz must be zero these bits must always be written with zeros. bit 0: isodisab iso endpoints disable isodisab=0 enables all 16 isochronous endpoints isodisab=1 disables all 16 isochronous endpoints, making the 2,048 bytes of isochro- nous fifo memory available as 8051 data memory at 0x2000-0x27ff. figure 12-13. zero byte count register bits 0-7: ep(n) zero byte count for iso out endpoints the 8051 can check these bits as a fast way to check all of the out isochronous endpoints at once for no data received during the previous frame. a 1 in any bit position means that a zero byte isochronous out packet was received for the indicated endpoint. isoctl isochronous control 7fa1 b7 b6 b5 b4 b3 b2 b1 b0 - - - - ppstat mbz mbz isodisab r r r r r r/w r/w r/w 0 0 0 0 0 0 0 0 zbcout zero byte count bits 7fa2 b7 b6 b5 b4 b3 b2 b1 b0 ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8 r r r r r r r r x x x x x x x x
page 12-16 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-14. i 2 c transfer registers the 8051 uses these registers to transfer data over the ez-usb i 2 c bus. bit 7: start signal start condition the 8051 sets the start bit to 1 to prepare an i 2 c bus transfer. if start=1, the next 8051 load to i2dat will generate the start condition followed by the serialized byte of data in i2dat. the 8051 loads byte data into i2dat after setting the start bit. the i 2 c controller clears the start bit during the ack interval. bit 6: stop signal stop condition the 8051 sets stop=1 to terminate an i 2 c bus transfer. the i 2 c controller clears the stop bit after completing the stop condition. if the 8051 sets the stop bit during a byte transfer, the stop condition will be generated immediately following the ack phase of the byte transfer. if no byte transfer is occurring when the stop bit is set, the stop condition will be carried out immediately on the bus. data should not be written to i2cs or i2dat until the stop bit returns low. 12.10 i 2 c registers i2cs i 2 c control and status 7fa5 b7 b6 b5 b4 b3 b2 b1 b0 start stop lastrd id1 id0 berr ack done r/w r/w r/w r r r r r 0 0 0 x x 0 0 0 i2dat i 2 c data 7fa6 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-17 bit 5: lastrd last data read to read data over the i 2 c bus, an i 2 c master floats the sda line and issues clock pulses on the scl line. after every eight bits, the master drives sda low for one clock to indicate ack. to signal the last byte of the read transfer, the master floats sda at ack time to instruct the slave to stop sending. this is controlled by the 8051 by setting lastrd=1 before reading the last byte of a read transfer. the i 2 c controller clears the lastrd bit at the end of the transfer (at ack time). bit 4-3: id1,id0 boot eeprom id these bits are set by the boot loader to indicate whether an 8-bit address or 16-bit address eeprom at slave address 000 or 001 was detected at power-on. normally, they are used for debug purposes only. bit 2: berr bus error this bit indicates an i 2 c bus error. berr=1 indicates that there was bus contention, which results when an outside device drives the bus lo when it shouldnt, or when another bus master wins arbitration, taking control of the bus. berr is cleared when 8051 reads or writes the idata register. bit 1: ack acknowledge bit every ninth scl or a write transfer the slave indicates reception of the byte by asserting ack. the ez-usb controller floats sda during this time, samples the sda line, and updates the ack bit with the complement of the detected value. ack=1 indicates acknowledge, and ack=0 indicates not-acknowledge. the ez-usb core updates the ack bit at the same time it sets done=1. the ack bit should be ignored for read trans- fers on the bus. note setting lastrd does not automatically generate a stop condition. the 8051 should also set the stop bit at the end of a read transfer.
page 12-18 chapter 12. ez-usb registers ez-usb trm v1.9 bit 0: done i 2 c transfer done the i 2 c controller sets this bit whenever it completes a byte transfer, right after the ack stage. the controller also generates an i 2 c interrupt request (8051 int3) when it sets the done bit. the i 2 c controller automatically clears the done bit and the i 2 c interrupt request bit whenever the 8051 reads or writes the i2dat register. figure 12-15. i 2 c mode register the i 2 c interrupt includes one additional interrupt source in the an2122/an2126, a 1-0 transition of the stop bit. to enable this interrupt, set the stopie bit in the i2cmode register. the 8051 determines the interrupt source by checking the done and stop bits in the i2cs register. i2cmode i 2 c mode 7fa7 b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 0 0 stopie 0 r r r r r r r/w r 0 0 0 0 0 0 0 0
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-19 figure 12-16. interrupt vector register ivec indicates the source of an interrupt from the usb core. when the usb core gener- ates an int2 (usb) interrupt request, it updates ivec to indicate the source of the inter- rupt. the interrupt sources are encoded on iv[4..0] as shown in figure 9-2. 12.11 interrupts ivec interrupt vector 7fa8 b7 b6 b5 b4 b3 b2 b1 b0 0 iv4 iv3 iv2 iv1 iv0 0 0 r r r r r r r r 0 0 0 0 0 0 0 0
page 12-20 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-17. in/out interrupt request (irq) registers these interrupt request (irq) registers indicate the pending interrupts for each bulk end- point. an interrupt request (ir) bit becomes active when the bsy bit for an endpoint makes a transition from one to zero (the endpoint becomes un-busy , giving access to the 8051). the ir bits function independently of the interrupt enable (ie) bits, so interrupt requests are held whether or not the interrupts are enabled. the 8051 clears an interrupt request bit by writing a 1 to it (see the following note). in07irq endpoint 0-7 in interrupt request 7fa9 b7 b6 b5 b4 b3 b2 b1 b0 in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 out07irq endpoint 0-7 out interrupt requests 7faa b7 b6 b5 b4 b3 b2 b1 b0 out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note do not clear an irq bit by reading an irq register, oring its contents with a bit mask, and writing back the irq register. this will clear all pending interrupts. instead, sim- ply write the bit mask value (with the irq you want to clear) directly to the irq register.
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-21 * an2122/an2126 only. figure 12-18. usb interrupt request (irq) registers usbirq indicates the interrupt request status of the usb reset, suspend, setup token, start of frame, and setup data available interrupts. bit 5: ibnir in bulk nak interrupt request this bit is in the an2122 and an2126 versions only. the ez-usb core sets this bit when any of the in bulk endpoints responds to an in token with a nak. this interrupt occurs when the host sends an in token to a bulk in endpoint which has not been armed by the 8051 writing its byte count register. individual enables and requests (per endpoint) are controlled by the ibnirq and ibnien registers (7fb0, 7fb1). bit 4: uresir usb reset interrupt request the ez-usb core sets this bit to 1 when it detects a usb bus reset. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to 0 by a power-on reset. write a 1 to this bit to clear the interrupt request. see chapter 10, "ez-usb resets" for more information about this bit. bit 3: suspir usb suspend interrupt request the ez-usb core sets this bit to 1 when it detects usb suspend signaling (no bus activity for 3 ms). write a 1 to this bit to clear the interrupt request. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to 0 by a power-on reset. see chapter 11, "ez- usb power management" for more information about this bit. usbirq usb interrupt request 7fab b7 b6 b5 b4 b3 b2 b1 b0 - - ibnir* uresir suspir sutokir sofir sudavir r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
page 12-22 chapter 12. ez-usb registers ez-usb trm v1.9 bit 2: sutokir setup token interrupt request the ez-usb core sets this bit to 1 when it receives a setup token. write a 1 to this bit to clear the interrupt request. see chapter 7, "ez-usb endpoint zero" for more infor- mation on the handling of setup tokens. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to 0 by a power-on reset. bit 1: sofir start of frame interrupt request the ez-usb core sets this bit to 1 when it receives a sof packet. write a 1 to this bit to clear the interrupt condition. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to 0 by a power-on reset. bit 0: sudavir setup data available interrupt request the ez-usb core sets this bit to 1 when it has transferred the eight data bytes from an endpoint zero setup packet into internal registers (at setupdat). write a 1 to this bit to clear the interrupt condition. because this bit can change state while the 8051 is in reset, it may be active when the 8051 comes out of reset, although it is reset to 0 by a power-on reset.
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-23 figure 12-19. in/out interrupt enable registers the endpoint interrupt enable registers define which endpoints have active interrupts. they do not affect the endpoint action, only the generation of an interrupt in response to endpoint events. when the ien bit for an endpoint is 0, the interrupt request bit for that endpoint is ignored, but saved. when the ien bit for an endpoint is 1, any irq bit equal to 1 gen- erates an 8051 int2 request. in07en endpoint 0-7 in interrupt enables 7fac b7 b6 b5 b4 b3 b2 b1 b0 in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 out07ien endpoint 0-7 out interrupt enables 7fad b7 b6 b5 b4 b3 b2 b1 b0 out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note the int2 interrupt (eie.0) and the 8051 global interrupt enable (ea) must be enabled for the endpoint interrupts to propagate to the 8051. once the int2 interrupt is active, it must be cleared by software.
page 12-24 chapter 12. ez-usb registers ez-usb trm v1.9 * an2122/an2126 only. figure 12-20. usb interrupt enable register usbien bits gate the interrupt request to the 8051 for usb reset, suspend, setup token, start of frame, and setup data available. bit 5: ibnie in bulk nak interrupt enable this bit is in the an2122 and an2126 versions only. the 8051 sets this bit to enable the in-bulk-nak interrupt. this interrupt occurs when the host sends an in token to a bulk in endpoint which has not been armed by the 8051 writing its byte count register. indi- vidual enables and requests (per endpoint) are controlled by the ibnirq and ibnien reg- isters (7fb0, 7fb1). bit 4: uresie usb reset interrupt enable this bit is the interrupt mask for the uresir bit. when this bit is 1, the interrupt is enabled, when it is 0, the interrupt is disabled. bit 3: suspie usb suspend interrupt enable this bit is the interrupt mask for the suspir bit. when this bit is 1, the interrupt is enabled, when it is 0, the interrupt is disabled. bit 2: sutokie setup token interrupt enable this bit is the interrupt mask for the sutokir bit. when this bit is 1, the interrupt is enabled, when it is 0, the interrupt is disabled. usbien usb interrupt enable 7fae b7 b6 b5 b4 b3 b2 b1 b0 - - ibnie* uresie suspie sutokie sofie sudavie r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-25 bit 1: sofie start of frame interrupt enable this bit is the interrupt mask for the sofie bit. when this bit is 1, the interrupt is enabled, when it is 0, the interrupt is disabled. bit 0: sudavie setup data available interrupt enable this bit is the interrupt mask for the sudavie bit. when this bit is 1, the interrupt is enabled, when it is 0, the interrupt is disabled.
page 12-26 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-21. breakpoint and autovector register bit 3: break breakpoint enable the break bit is set when the 8051 address bus matches the address held in the bit breakpoint address registers (next page). the bkpt pin reflects the state of this bit. the 8051 writes a 1 to the break bit to clear it. it is not necessary to clear the break bit if the pulse mode bit (bppulse) is set. bit 2: bppulse breakpoint pulse mode the 8051 sets this bit to 1 to pulse the break bit (and bkpt pin) high for 8 clk24 cycles when the 8051 address bus matches the address held in the breakpoint address reg- isters. when this bit is set to 0, the break bit (and bkpt pin) remains high until it is cleared by the 8051. bit 1: bpen breakpoint enable if this bit is 1, a break signal is generated whenever the 16-bit address lines match the value in the breakpoint address registers (bpaddrh/l). the behavior of the break bit and associated bkpt pin signal is either latched or pulsed, depending on the state of the bppulse bit. bit 0: aven auto-vector enable if this bit is 1, the ez-usb auto-vector feature is enabled. if it is 0, the auto-vector fea- ture is disabled. see chapter 9, "ez-usb interrupts" for more information on the auto- vector feature. usbbav breakpoint and autovector 7faf b7 b6 b5 b4 b3 b2 b1 b0 - - - - break bppulse bpen av e n r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-27 * an2122/an2126 only. figure 12-22. in bulk nak interrupt request register these bits are set when a bulk in endpoint (0-6) received an in token while the endpoint was not armed for data transfer. in this case the sie automatically sends a nak response, and sets the corresponding ibnirq bit. if the ibn interrupt is enabled (usbien.5=1), and the endpoint interrupt is enabled in the ibnien register, an interrupt is request gener- ated. the 8051 can test the ibnirq register to determine which of the endpoints caused the interrupt. the 8051 clears an ibnirq bit by writing a 1 to it. figure 12-23. in bulk nak interrupt enable register each of the individual in endpoints may be enabled for an ibn interrupt using the ibnen register. the 8051 sets an interrupt enable bit to 1 to enable the corresponding interrupt. ibnirq in bulk nak interrupt requests 7fb0 b7 b6 b5 b4 b3 b2 b1 b0 - ep6in ep5in ep4in ep3in ep2in ep1in ep0in r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x ibnien in bulk nak interrupt enables 7fb1 b7 b6 b5 b4 b3 b2 b1 b0 - ep6in ep5in ep4in ep3in ep2in ep1in ep0in r/w r/w r/w r/w r/w r/w r/w r/w x x 0 0 0 0 0 0
page 12-28 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-24. in/out interrupt enable registers when the current 16-bit address (code or xdata) matches the bpaddrh/bpaddrl address, a breakpoint event occurs. the bppulse and bpen bits in the usbbav regis- ter control the action taken on a breakpoint event. if the bpen bit is 0, address breakpoints are ignored. if bpen is 1 and bppulse is 1, an 8 clk24 wide pulse appears on the bkpt pin. if bpen is 1 and bppulse is 0, the bkpt pin remains active until the 8051 clears the break bit by writing 1 to it. bpaddrh breakpoint address high 7fb2 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 bpaddrl breakpoint address low 7fb3 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-29 figure 12-25. port configuration registers these registers control ez-usb control endpoint zero. because endpoint zero is a bi- directional endpoint, the in and out functionality is controlled by a single control and status (cs) register, unlike endpoints 1-7, which have separate incs and outcs regis- ters. bit 3: outbsy out endpoint busy outbsy is a read-only bit that is automatically cleared when a setup token arrives. the 8051 sets the outbsy bit by writing a byte count to epoutbc. 12.12 endpoint 0 control and status registers ep0cs endpoint zero control and status 7fb4 b7 b6 b5 b4 b3 b2 b1 b0 - - - - outbsy inbsy hsnak ep0stall r r r r r r r/w r/w 0 0 0 0 1 0 0 0 in0bc endpoint zero in byte count 7fb5 b7 b6 b5 b4 b3 b2 b1 b0 - bc6 bc5 bc4 bc3 bc2 bc1 bc0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0 out0bc endpoint zero out byte count 7fc5 b7 b6 b5 b4 b3 b2 b1 b0 - bc6 bc5 bc4 bc3 bc2 bc1 bc0 r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 0 0 0
page 12-30 chapter 12. ez-usb registers ez-usb trm v1.9 if the control transfer uses an out data phase, the 8051 must load a dummy byte count into out0bc to arm the out endpoint buffer. until it does, the ez-usb core will nak the out tokens. bit 2: inbsy in endpoint busy inbsy is a read-only bit that is automatically cleared when a setup token arrives. the 8051 sets the inbsy bit by writing a byte count to in0bc. if the control transfer uses an in data phase, the 8051 loads the requested data into the in0buf buffer, and then loads the byte count into in0bc to arm the data phase of the control transfer. alternatively, the 8051 can arm the data transfer by loading an address into the setup data pointer registers sudptrh/l. until armed, the ez-usb core will nak the in tokens. bit 1: hsnak handshake nak hsnak (handshake nak) is a read/write bit that is automatically set when a setup token arrives. the 8051 clears hsnak by writing a 1 to the register bit. while hsnak=1, the ez-usb core naks the handshake (status) phase of the con- trol transfer. when hsnak=0, it acks the handshake phase. the 8051 can clear hsnak at any time during a control transfer. bit 0: ep0stall endpoint zero stall ep0stall is a read/write bit that is automatically cleared when a setup token arrives. the 8051 sets ep0stall by writing a 1 to the register bit. while ep0stall=1, the ez-usb core sends the stall pid for any in or out token. this can occur in either the data or handshake phase of the control transfer. note to indicate an endpoint stall on endpoint zero, set both ep0stall and hsnak bits. setting the ep0stall bit alone causes endpoint zero to nak forever because the host keeps the control transfer pending.
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-31 endpoints 1-7 in and out are used for bulk or interrupt data. table 12-5 shows the addresses for the control/status and byte count registers associated with these endpoints. the bi-directional control endpoint zero registers are described in section 12.12, "endpoint 0 control and status registers." 12.13 endpoint 1-7 control and status registers table 12-5. control and status register addresses for endpoints 0-7 address function name 7fb4 control and status - endpoint in0 ep0cs 7fb5 byte count - endpoint in0 in0bc 7fb6 control and status - endpoint in1 in1cs 7fb7 byte count - endpoint in1 in1bc 7fb8 control and status - endpoint in2 in2cs 7fb9 byte count - endpoint in2 in2bc 7fba control and status - endpoint in3 in3cs 7fbb byte count - endpoint in3 in3bc 7fbc control and status - endpoint in4 in4cs 7fbd byte count - endpoint in4 in4bc 7fbe control and status - endpoint in5 in5cs 7fbf byte count - endpoint in5 in5bc 7fc0 control and status - endpoint in6 in6cs 7fc1 byte count - endpoint in6 in6bc 7fc2 control and status - endpoint in7 in7cs 7fc3 byte count - endpoint in7 in7bc 7fc4 reserved 7fc5 byte count - endpoint out0 out0bc 7fc6 control and status - endpoint out1 out1cs 7fc7 byte count - endpoint out1 out1bc 7fc8 control and status - endpoint out2 out2cs 7fc9 byte count - endpoint out2 out2bc 7fca control and status - endpoint out3 ou37cs 7fcb byte count - endpoint out3 out3bc 7fcc control and status - endpoint out4 out4cs 7fcd byte count - endpoint out4 out4bc 7fce control and status - endpoint out5 out5cs 7fcf byte count - endpoint out5 out5bc 7fd0 control and status - endpoint out6 out6cs 7fd1 byte count - endpoint out6 out6bc 7fd2 control and status - endpoint out7 out7cs 7fd3 byte count - endpoint out7 out7bc
page 12-32 chapter 12. ez-usb registers ez-usb trm v1.9 * see table 12-5 for individual control/status register addresses. figure 12-26. in control and status registers bit 1: innbsy in endpoint (1-7) busy the bsy bit indicates the status of the endpoints in buffer innbuf. the ez-usb core sets bsy=0 when the endpoints in buffer is empty and ready for loading by the 8051. the 8051 sets bsy=1 by loading the endpoints byte count register. when bsy=1, the 8051 should not write data to an in endpoint buffer, because the end- point fifo could be in the act of transferring data to the host over the usb. bsy=0 when the usb in transfer is complete and endpoint ram data is available for 8051 access. usb in tokens for the endpoint are nakd while bsy=0 (the 8051 is still loading data into the endpoint buffer). a 1-to-0 transition of bsy (indicating that the 8051 can access the buffer) generates an interrupt request for the in endpoint. after the 8051 writes the data to be transferred to the in endpoint buffer, it loads the endpoints byte count register with the number of bytes to transfer, which automatically sets bsy=1. this enables the in transfer of data to the host in response to the next in token. again, the cpu should never load endpoint data while bsy=1. the 8051 writes a 1 to an in endpoint busy bit to disarm a previously armed endpoint. (this sets bsy=0.) the 8051 program should do this only after a usb bus reset, or when the host selects a new interface or alternate setting that uses the endpoint. this prevents stale data from a previous setting from being accepted by the hosts first in transfer that uses the new setting. to disarm a paired in endpoint, write a 1 to the busy bit for both endpoints in the pair. inncs endpoint (1-7) in control and status 7fb6-7fc2* b7 b6 b5 b4 b3 b2 b1 b0 - - - - - - innbsy innstl r r r r r r r/w r/w 0 0 0 0 0 0 0 0 note: even though the register description shows bit 1 as r/w, the 8051 can only clear this bit by writing a 1 to it. the 8051 can not directly set this bit.
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-33 bit 0: innstl in endpoint (1-7) stall the 8051 sets this bit to 1 to stall an endpoint, and to 0 to clear a stall. when the stall bit is 1, the ez-usb core returns a stall handshake for all requests to the endpoint. this notifies the host that something unexpected has happened. the 8051 sets an endpoints stall bit under two circumstances: 1. the host sends a set_featureendpoint stall request to the specific endpoint. 2. the 8051 encounters any show stopper error on the endpoint, and sets the stall bit to tell the host to halt traffic to the endpoint. the 8051 clears an endpoints stall bit under two circumstances: 1. the host sends a clear_feature--endpoint stall request to the specific endpoint. 2. the 8051 receives some other indication from the host that the stall should be cleared (this is referred to as host intervention in the usb specification). this indication could be a usb bus reset. all stall bits are automatically cleared when the ez-usb chip renumerates ? by pulsing the discon bit hi.
page 12-34 chapter 12. ez-usb registers ez-usb trm v1.9 * see table 12-5 for individual byte count register addresses. figure 12-27. in byte count registers the 8051 writes this register with the number of bytes it loaded into the in endpoint buffer innbuf. writing this register also arms the endpoint by setting the endpoint bsy bit to 1. legal values for these registers are 0-64. a zero transfer size is used to terminate a trans- fer that is an integral multiple of maxpacketsize. for example, a 256-byte transfer with maxpacketsize = 64, would require four packets of 64 bytes each plus one packet of 0 bytes. the in byte count should never be written while the endpoints busy bit is set. when the register pairing feature is used (section 6, "ez-usb bulk transfers") in2bc is used for the ep2/ep3 pair, in4bc is used for the ep4/ep5 pair, and in6bc is used for the ep6/ep7 pair. in the paired (double-buffered) mode, after the first write to the even-num- bered byte count register, the endpoint bsy bit remains at 0, indicating that only one of the buffers is full, and the other is still empty. the odd numbered byte count register is not used when endpoints are paired. innbc endpoint (1-7) in byte count 7fb7-7fc3* b7 b6 b5 b4 b3 b2 b1 b0 - d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-35 * see table 12-5 for individual control/status register addresses. figure 12-28. out control and status registers bit 1: outnbsy out endpoint (1-7) busy the bsy bit indicates the status of the endpoints out buffer outnbuf. the ez-usb core sets bsy=0 when the host data is available in the out buffer. the 8051 sets bsy=1 by loading the endpoints byte count register. when bsy=1, endpoint ram data is invalid--the endpoint buffer has been emptied by the 8051 and is waiting for new out data from the host, or it is the process of being loaded over the usb. bsy=0 when the usb out transfer is complete and endpoint ram data in outnbuf is available for the 8051 to read. usb out tokens for the endpoint are nakd while bsy=1 (the 8051 is still reading data from the out endpoint). a 1-to-0 transition of bsy (indicating that the 8051 can access the buffer) generates an interrupt request for the out endpoint. after the 8051 reads the data from the out end- point buffer, it loads the endpoints byte count register with any value to re-arm the end- point, which automatically sets bsy=1. this enables the out transfer of data from the host in response to the next out token. the cpu should never read endpoint data while bsy=1. bit 0: outnstl out endpoint (1-7) stall the 8051 sets this bit to 1 to stall an endpoint, and to 0 to clear a stall. when the stall bit is 1, the ez-usb core returns a stall handshake for all requests to the endpoint. this notifies the host that something unexpected has happened. the 8051 sets an endpoints stall bit under two circumstances: 1. the host sends a set_featureendpoint stall request to the specific endpoint. outncs endpoint (1-7) out control and status 7fc6-7fd2* b7 b6 b5 b4 b3 b2 b1 b0 - - - - - - outnbsy outnstl r r r r r r r r/w 0 0 0 0 0 0 0 0
page 12-36 chapter 12. ez-usb registers ez-usb trm v1.9 2. the 8051 encounters any show stopper error on the endpoint, and sets the stall bit to tell the host to halt traffic to the endpoint. the 8051 clears an endpoints stall bit under two circumstances: 1. the host sends a clear_featureendpoint stall request to the specific endpoint. 2. the 8051 receives some other indication from the host that the stall should be cleared (this is referred to as host intervention in the usb specification). all stall bits are automatically cleared when the ez-usb chip renumerates ? . * see table 12-5 for individual control/status register addresses. figure 12-29. out byte count registers the 8051 reads this register to determine the number of bytes sent to an out endpoint. legal sizes are 0 - 64 bytes. each ez-usb bulk out endpoint has a byte count register, which serves two purposes. the 8051 reads the byte count register to determine how many bytes were received during the last out transfer from the host. the 8051 writes the byte count register (with any value) to tell the ez-usb core that it has finished reading bytes from the buffer, making the buffer available to accept the next out transfer. writing the byte count register sets the endpoints bsy bit to 1. when the register-pairing feature is used, out2bc is used for the ep2/ep3 pair, out4bc is used for the ep4/ep5 pair, and out6bc is used for the ep6/ep7 pair. the odd-numbered byte count registers should not be used. when the 8051 writes a byte to the even numbered byte count register, the ez-usb core switches buffers. if the other buffer already contains data to be read by the 8051, the outnbsy bit remains at 0. all out tokens are nakd until the 8051 is released from reset, whereupon the ack/ nak behavior is based on pairing. outnbc endpoint (1-7) out byte count 7fc7-7fd3* b7 b6 b5 b4 b3 b2 b1 b0 - d6 d5 d4 d3 d2 d1 d0 r r r r r r r r/w 0 0 0 0 0 0 0 0
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-37 figure 12-30. setup data pointer high/low registers when the ez-usb chip receives a get_descriptor request on endpoint zero, it can instruct the ez-usb core to handle the multi-packet in transfer by loading these registers with the address of an internal table containing the descriptor data. the descriptor data tables may be placed in internal program/data ram or in unused endpoint 0-7 ram .the sudptr does not operate with external memory. the sudptr registers should be loaded in high/low order. in addition to loading sudptrl, the 8051 must also clear the hsnak bit in the ep0cs register (by writing a 1 to it) to complete the control transfer. 12.14 global usb registers sudptrh setup data pointer high 7fd4 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x sudptrl setup data pointer low 7fd5 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note any host request that uses the ez-usb setup data pointer to transfer in data must indi- cate the number of bytes to transfer in bytes 6 (wlenghthl) and 7 (wlengthh) of the setup packet. these bytes are pre-assigned in the usb specification to be length bytes in all standard device requests such as get_descriptor. if vendor-specific requests are used to transfer large blocks of data using the setup data pointer, they must include this pre-defined length field in bytes 6-7 to tell the ez-usb core how many bytes to transfer using the setup data pointer.
page 12-38 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-31. usb control and status registers bit 7: wakesrc wakeup source this bit indicates that a high to low transaction was detected on the wakeup# pin. writ- ing a 1 to this bit resets it to 0. bit 3: discon signal a disconnect on the discon# pin the ez-usb discon# pin reflects the complement of this bit. this bit is normally set to 0 so that the action of the discoe bit (below) either floats the discon# pin or drives it hi. bit 2: discoe disconnect output enable discoe controls the output buffer on the discon# pin. when discoe=0, the pin floats, and when discoe=1, it drives to the complement of the discon bit (above). discoe is used in conjunction with the renum bit to perform renumeration ? (chap- ter 5, "ez-usb enumeration and renumeration ? "). usbcs usb control and status 7fd6 b7 b6 b5 b4 b3 b2 b1 b0 wa k e s r c - - - discon discoe renum sigrsume r/w r r r r/w r/w r/w r/w 0 0 0 0 0 1 0 0
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-39 bit 1: renum renumerate this bit controls which entity, the usb core or the 8051, handles usb device requests. when renum=0, the ez-usb core handles all device requests. when renum=1, the 8051 handles all device requests except set_address. the 8051 sets renum=1 during a bus disconnect to transfer usb control to the 8051. the ez-usb core automatically sets renum=1 under two conditions: 1. completion of a b2 boot load (chapter 5, "ez-usb enumeration and renumer- ation ? "). 2. when external memory is used (ea=1) and no boot i 2 ceepromisused(see section 10.3.3, "external rom"). bit 0: sigrsume signal remote device resume the 8051 sets sigrsume=1 to drive the k state onto the usb bus. this should be done only by a device that is capable of remote wakeup, and then only during the sus- pend state. to signal resume, the 8051 sets sigrsume=1, waits 10-15 ms, then sets sigrsume=0.
page 12-40 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-32. data toggle control register bit 7: q data toggle value q=0 indicates data0 and q=1 indicates data1, for the endpoint selected by the io and ep[2..0] bits. the 8051 writes the endpoint select bits (io and ep[2..0]), before reading this value. bit 6: s set data toggle to data1 after selecting the desired endpoint by writing the endpoint select bits (io and ep[2..0]) the 8051 sets s=1 to set the data toggle to data1. the endpoint selection bits should not be changed while this bit is written. bit 5: r set data toggle to data0 after selecting the desired endpoint by writing the endpoint select bits (io and ep[2..0]) the 8051 sets r=1 to set the data toggle to data0. the endpoint selection bits should not be changed while this bit is written. for advice on when to reset the data toggle, see chap- ter 7, "ez-usb endpoint zero." bit 4: io select in or out endpoint the 8051 sets this bit to select an endpoint direction prior to setting its r or s bit. io=0 selects an out endpoint, io=1 selects an in endpoint. togctl data toggle control 7fd7 b7 b6 b5 b4 b3 b2 b1 b0 q s r io 0 ep2 ep1 ep0 r r/w r/w r/w r/w r/w r/w r/w x x x x x x x x note at this writing there is no known reason to set an endpoint data toggle to 1. this bit is provided for generality and testing only.
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-41 bit 2-0: ep select endpoint the 8051 sets these bits to select an endpoint prior to setting its r or s bit. valid values are 0-7 to correspond to bulk endpoints in0-in7 and out0-out7. figure 12-33. usb frame count high/low registers every millisecond the host sends a sof token indicating start of frame, along with an 11-bit incrementing frame count. the ez-usb copies the frame count into these registers at every sof. one use of the frame count is to respond to the usb sync_frame request (chapter 7, "ez-usb endpoint zero"). if the usb core detects a missing or garbled sof, it generates an internal sof and incre- ments usbframel-usbrameh. usbframel usb frame count low 7fd8 b7 b6 b5 b4 b3 b2 b1 b0 fc7 fc6 fc5 fc4 fc3 fc2 fc1 fc0 r r r r r r r r x x x x x x x x usbframeh usb frame count high 7fd9 b7 b6 b5 b4 b3 b2 b1 b0 0 0 0 0 0 fc10 fc9 fc8 r r r r r r r r x x x x x x x x
page 12-42 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-34. function address register during the usb enumeration process, the host sends a device a unique 7-bit address, which the ez-usb core copies into this register. there is normally no reason for the cpu to know its usb device address because the usb core automatically responds only to its assigned address. fnaddr function address 7fdb b7 b6 b5 b4 b3 b2 b1 b0 0 fa6 fa5 fa 4 fa 3 fa 2 fa 1 fa0 r r r r r r r r x x x x x x x x note during renumeration ? the usb core sets register to 0 to allow the ez-usb chip to respond to the default address 0.
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-43 figure 12-35. usb endpoint pairing register bit 7: isosend0 isochronous send zero length data packet the isosend0 bit is used when the ez-usb chip receives an isochronous in token while the in fifo is empty. if isosend0=0 (the default value), the ez-usb core does not respond to the in token. if isosend0=1, the ez-usb core sends a zero-length data packet in response to the in token. which action to take depends on the overall system design. the isosend0 bit applies to all of the isochronous in endpoints, in8buf through in15buf. bit 5-3: prnout pair bulk out endpoints set the endpoint pairing bits (prxout) to 1 to enable double-buffering of the bulk out endpoint buffers. with double buffering enabled, the 8051 can operate on one buffer while another is being transferred over usb. the endpoint busy and interrupt request bits function identically, so the 8051 code requires no code modification to support double buffering. when an endpoint is paired, the 8051 uses only the even-numbered endpoint of the pair. the 8051 should not use the paired odd endpoints irq, ien, valid bits or the buffer associated with the odd numbered endpoint. bit 2-0: prnin pair bulk in endpoints set the endpoint pairing bits (prxin) to 1 to enable double-buffering of the bulk in endpoint buffers. with double buffering enabled, the 8051 can operate on one buffer while another is being transferred over usb. when an endpoint is paired, the 8051 should access only the even-numbered endpoint of the pair. the 8051 should not use the irq, ien, valid bits or the buffer associated with the odd numbered endpoint. usbpair usb endpoint pairing 7fdd b7 b6 b5 b4 b3 b2 b1 b0 isosend0 - pr6out pr4out pr2out pr6in pr4in pr2in r/w r/w r/w r/w r/w r/w r/w r/w 0 x 0 0 0 0 0 0
page 12-44 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-36. in/out valid bits register the 8051 sets val=1 for any active endpoints, and val=0 for inactive endpoints. these bits instruct the ez-usb core to return a no response if an invalid endpoint is addressed, instead of a nak. the default values of these registers are set to support all endpoints that exist in the default usb device (see table 5-1). in07val endpoints 0-7 in valid bits 7fde b7 b6 b5 b4 b3 b2 b1 b0 in7val in6val in5val in4val in3val in2val in1val in0val r/w r/w r/w r/w r/w r/w r/w r/w 0 1 0 1 0 1 1 1 out07val endpoints 0-7 out valid bits 7fdf b7 b6 b5 b4 b3 b2 b1 b0 out7val out6val out5val out4val out3val out2val out1val out0val r/w r/w r/w r/w r/w r/w r/w r/w 0 1 0 1 0 1 0 1
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-45 figure 12-37. isochronous in/out endpoint valid bits register the 8051 sets val=1 for active endpoints, and val=0 for inactive endpoints. these bits instruct the ez-usb core to return a no response if an invalid endpoint is addressed. the default values of these registers are set to support all endpoints that exist in the default usb device (see table 5-1). inisoval isochronous in endpoint valid bits 7fe0 b7 b6 b5 b4 b3 b2 b1 b0 in15val in14val in13val in12val in11val in10val in9val in8val r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 1 1 1 outisoval isochronous out endpoint valid bits 7fe1 b7 b6 b5 b4 b3 b2 b1 b0 out15val out14val out13val out12val out11val out10val out9val out8val r/w r/w r/w r/w r/w r/w r/w r/w 0 0 0 0 0 1 1 1
page 12-46 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-38. fast transfer control register the ez-usb core provides a fast transfer mode that improves the8051 transfer speed between external logic and the isochronous and bulk endpoint buffers. the fastxfr register enables the modes for bulk and/or isochronous transfers, and selects the timing waveforms for the frd# and fwr# signals. bit 7: fiso enable fast iso transfers the 8051 sets fiso=1 to enable fast isochronous transfers for all16 isochronous endpoint fifos. when fiso=0, fast transfers are disabled for all 16 isochronous endpoints. bit 6: fblk enable fast bulk transfers the 8051 sets fblk=1 to enable fast bulk transfers using the autopointer (see section 12.16, "setup data") with bulk endpoints. when fblk=0 fast transfers are disabled for bulk endpoints. bit 5: rpol frd# pulse polarity the 8051 sets rpol=0 for active-low frd# pulses, and rpol=1 for active high frd# pulses. bit 4-3: rmod frd# pulse mode these bits select the phasing and width of the frd# pulse. see figure 8-12. 12.15 fast transfers fastxfr fast transfer control 7fe2 b7 b6 b5 b4 b3 b2 b1 b0 fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-47 bit 2: wpol fwr# pulse polarity the 8051 sets wpol=0 for active-low fwr# pulses, and wpol=1 for active high fwr# pulses. bit 1-0: wmod fwr# pulse mode these bits select the phasing and width of the fwr# pulse. see figure 8-11.
page 12-48 chapter 12. ez-usb registers ez-usb trm v1.9 figure 12-39. auto pointer registers these registers implement the ez-usb autopointer . autoptrh/l the 8051 loads a 16-bit address into the autoptrh/l registers. subsequent reads or writes to the autodata register increment the 16-bit value in these registers. the loaded address must be in internal ez-usb ram. the 8051 can read these registers to determine the address must be in internal ez-usb ram. the 8051 can read these regis- ters to determine the address of the next byte to be accessed via the autodata register. autodata 8051 data read or written to the autodata register accesses the memory addressed by the autoptrh/l registers, and increments the address after the read or write. these registers allow fifo access to the bulk endpoint buffers, as well as being useful for internal data movement. chapter 6, "ez-usb bulk transfers" and chapter 8, "ez-usb isochronous transfers" explain how to use the autopointer for fast transfers to and from the ez-usb endpoint buffers. autoptrh auto pointer address high 7fe3 b7 b6 b5 b4 b3 b2 b1 b0 a15 a14 a13 a12 a11 a10 a9 a8 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autoptrl auto pointer address low 7fe4 b7 b6 b5 b4 b3 b2 b1 b0 a7 a6 a5 a4 a3 a2 a1 a0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x autodata auto pointer data 7fe5 b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-49 figure 12-40. setup data buffer this buffer contains the 8 bytes of setup packet data from the most recently received control transfer. the data in setupbuf is valid when the sudavir (setup data available interrupt request) bit is set. the 8051 responds to the sudav interrupt by reading the setup bytes from this buffer. 12.16 setup data setupbuf setup data buffer (8 bytes) 7fe8-7fef b7 b6 b5 b4 b3 b2 b1 b0 d7 d6 d5 d4 d3 d2 d1 d0 r r r r r r r r x x x x x x x x
page 12-50 chapter 12. ez-usb registers ez-usb trm v1.9 * see table 12-6 for individual start address register addresses. figure 12-41. setup data buffer 12.17 isochronous fifo sizes outnaddr iso out endpoint start address 7ff0-7ff7* b7 b6 b5 b4 b3 b2 b1 b0 a9 a8 a7 a6 a5 a4 0 0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x innaddr iso in endpoint start address 7ff8-7fff* b7 b6 b5 b4 b3 b2 b1 b0 a9 a8 a7 a6 a5 a4 0 0 r/w r/w r/w r/w r/w r/w r/w r/w x x x x x x x x
ez-usb trm v1.9 chapter 12. ez-usb registers page 12-51 ez-usb isochronous endpoints use a pool of 1,024 double-buffered fifo bytes. the 1,024 fifo bytes can be divided between any or all of the isochronous endpoints. the 8051 sets isochronous endpoint fifo sizes by writing starting addresses to these registers, starting with address 0. address bits a3-a0 are internally set to zero, so the minimum fifo size is 16 bytes. see section 8.8, "fast transfer speed" for details about how to set these registers. table 12-6. isochronous fifo start address registers address endpoint start address 7ff0 endpoint 8 out start address 7ff1 endpoint 9 out start address 7ff2 endpoint 10 out start address 7ff3 endpoint 11 out start address 7ff4 endpoint 12 out start address 7ff5 endpoint 13 out start address 7ff6 endpoint 14 out start address 7ff7 endpoint 15 out start address 7ff8 endpoint 8 in start address 7ff9 endpoint 9 in start address 7ffa endpoint 10 in start address 7ffb endpoint 11 in start address 7ffc endpoint 12 in start address 7ffd endpoint 13 in start address 7ffe endpoint 14 in start address 7fff endpoint 15 in start address
page 12-52 chapter 12. ez-usb registers ez-usb trm v1.9
ez-usb trm v1.9 chapter 13. ez-usb ac/dc parameters page 13-1 13 ez-usb ac/dc parameters 13.1.1 absolute maximum ratings storagetemperature..............................-65 o c to +150 o c ambienttemperatureunderbias ....................-40 o cto+85 o c supply voltage to ground potential ...................-0.5vto+4.0v dc input voltage to any pin ........................-0.5vto+5.8v 13.1.2 operating conditions ta(ambienttemperatureunderbias).................. 0 o cto+70 o c supply voltage .................................. +3.0vto+3.6v groundvoltage.............................................0v f osc (oscillatororcrystalfrequency)..............12mhz+/-0.25% 13.1.3 dc characteristics 13.1 electrical characteristics table 13-1. dc characteristics symbol parameter condition min typ max unit notes v cc supply voltage 3.0 3.6 v v ih input high voltage 2 5.25 v v il input low voltage -.5 .8 v i i input leakage current 0 < v in page 13-2 chapter 13. ez-usb ac/dc parameters ez-usb trm v1.9 13.1.4 ac electrical characteristics specified conditions: capacitive load on all pins = 30 pf 13.1.5 general memory timing 13.1.6 program memory read 13.1.7 data memory read table 13-2. general memory timing symbol parameter min typ max unit notes tcl 1/clk24 frequency 41.66 ns tav delay from clock to valid address 0 10 ns tcd delay from clk24 to cs# 2 15 ns toed delay from clk24 to oe# 2 15 ns twd delay from clk24 to wr# 2 15 ns trd delay from clk24 to rd# 2 15 ns tpd delay from clk24 to psen# 2 15 ns table 13-3. program memory read symbol parameter formula min max unit notes taa1 address access time 3tcl-tav-tdsu1 103 ns tah1 address hold from clk24 tcl+1 42 ns tdsu1 data setup to clk24 12 ns tdh1 data hold from clk24 0 ns table 13-4. data memory read symbol parameter formula min max unit notes taa2 address access time 3tcl-tav-tdsu1 103 ns tah2 address hold from clk24 tcl+1 42 ns tdsu2 data setup to clk24 12 ns tdh2 data hold from clk24 0 ns
ez-usb trm v1.9 chapter 13. ez-usb ac/dc parameters page 13-3 13.1.8 data memory write 13.1.9 fast data write 13.1.10 fast data read table 13-5. data memory write symbol parameter formula min max unit notes tah3 address hold from clk24 tcl+2 43 ns tdv clk24 to data valid 15 ns tdvz clk24 to high impedance tcl+16 57 ns table 13-6. fast data write symbol parameter conditions min max unit notes tcdo clock to data output delay 3 15 ns tcwo clock to fifo write output delay 210ns tpfwd propagation delay difference fromfifowritetodataout 1ns table 13-7. fast data read symbol parameter conditions min max unit notes tcro clock to fifo read output delay 210ns tdsu4 data setup to rising clk24 12 ns tdh4 data hold to rising clk24 2 ns
page 13-4 chapter 13. ez-usb ac/dc parameters ez-usb trm v1.9 figure 13-1. external memory timing figure 13-2. program memory read timing clk24 a [15.0] tcl cs# tav tcd tcd oe# toed toed wr# twd twd rd# trd trd psen# tpd tpd clk24 tcl tah1 tdh1 tdsu1 oe# taa1
ez-usb trm v1.9 chapter 13. ez-usb ac/dc parameters page 13-5 figure 13-3. data memory read timing figure 13-4. data memory write timing clk24 a [15.0] tcl tah2 rd# d [7.0] tdh2 tdsu2 cs# oe# taa2 clk24 a [15.0] tcl tah3 cs# d [7.0] tdvz tdv wr#
page 13-6 chapter 13. ez-usb ac/dc parameters ez-usb trm v1.9 figure 13-5. fast transfer mode block diagram clk24 d [7:0] fwr# ez-usb an2131q asic 80 pqfp ez-usb fast transfer block diagram fifo clock d [7:0] fifo write stobe frd# fifo read stobe
ez-usb trm v1.9 chapter 13. ez-usb ac/dc parameters page 13-7 figure 13-6. fast transfer read timing [mode 00] figure 13-7. fast transfer write timing [mode 00] clk24 d[7..0] frd#[00] tcl input tdsu4 tdh4 tcro clk24 d[7..0] fwr#[00] tcl output tcdo tcdo tcwo tcwo
page 13-8 chapter 13. ez-usb ac/dc parameters ez-usb trm v1.9 figure 13-8. fast transfer read timing [mode 01] figure 13-9. fast transfer write timing [mode 01] clk24 d[7..0] frd#[01] tcl input tdsu4 tdh4 tcro clk24 d[7..0] fw r#[01] tcl output tcdo tcdo tcwo tcwo tpfwd
ez-usb trm v1.9 chapter 13. ez-usb ac/dc parameters page 13-9 figure 13-10. fast transfer read timing [mode 10] figure 13-11. fast transfer write timing [mode 10] clk24 d[7..0] frd#[10] tcl input tdsu4 tdh4 tcro clk24 d[7..0] fwr#[10] tcl output tcdo tcdo tcwo tcwo
page 13-10 chapter 13. ez-usb ac/dc parameters ez-usb trm v1.9 figure 13-12. fast transfer read timing [mode 11] figure 13-13. fast transfer write timing [mode 11] clk24 d[7..0] frd#[11] tcl input tdsu4 tdh4 tcro clk24 d[7..0] fw r#[11] tcl output tcdo tcdo tcwo tcwo tpfwd
ez-usb trm v1.9 chapter 14. ez-usb packaging page 14-1 14 ez-usb packaging figure 14-1. 44-pin pqfp package (top view) figure 14-2. 44-pin pqfp package (side view) 14.1 44-pin pqfp package 1 10.10 9.90 13.45 12.95 8.00 ref 11 33 23 12 22 44 34 0.80 bsc. 2.35 max see lead detail 0.45 0.30
page 14-2 chapter 14. ez-usb packaging ez-usb trm v1.9 figure 14-3. 44-pin pqfp package (detail view) 0 o ~7 o 0.95 0.65 1.60 typ lead detail: a(s=n/s) 2.10 1.95 0.25 0.10 0.23 0.13
ez-usb trm v1.9 chapter 14. ez-usb packaging page 14-3 figure 14-4. 80-pin pqfp package (top view) figure 14-5. 80-pin pqfp package (side view) 14.2 80-pin pqfp package 3.0 3.0 80 pqfp 0.80 1.00 ref 124 25 40 64 41 80 65 0.80 bsc. 24.10 23.70 20.05 19.95 14.05 13.95 18.10 17.70 3.04 max 0.42 0.32 see lead detail
page 14-4 chapter 14. ez-usb packaging ez-usb trm v1.9 figure 14-6. 80-pin pqfp package (detail view) 0 o ~7 o 1.00 0.80 1.95 + 0.15 detail "a" 2.76 2.66 0.28 0.18 8 places 12 o ref. base plane seating plane 0 o ~10 o 0.25 gage plane
ez-usb trm v1.9 chapter 14. ez-usb packaging page 14-5 figure 14-7. 48-pin tqfp package (side view) figure 14-8. 48-pin tqfp package (top view) 14.3 48-pin tqfp package 1.60 max see lead detail 0.27 0.17 all dimensions in millimeters. 1 12 36 25 13 24 48 37 0.50 bsc. 48 tqfp 9.00 bsc. 7.00 bsc. all dimensions in millimeters.
page 14-6 chapter 14. ez-usb packaging ez-usb trm v1.9 figure 14-9. 48-pin tqfp package (detail view) 0.05 0.15 1.35 1.45 0.08 0.20 0 o min. 0.08 r. min. 0.20 min. r. 0-7 o 1.00 ref. 0.45 0.75 seating plane base plane 48-pin lead detail all dimensions in millimeters. 0.25 gauge plane
ez-usb trm v1.9 table of contents i ez-usb v 1.9 appendices table of contents appendix a: 8051introduction...............................a-1 a.1 introduction ............................................................................................ a-1 a.2 8051 features ......................................................................................... a-1 a.3 performance overview .......................................................................... a-2 a.4 software compatibility .......................................................................... a-3 a.5 803x/805x feature comparison ............................................................. a-4 a.6 8051 core/ds80c320 differences ........................................................ a-5 a.6.1 serial ports ....................................................................................... a-5 a.6.2 timer 2 ............................................................................................. a-5 a.6.3 timed access protection ................................................................. a-5 a.6.4 watchdog timer .............................................................................. a-5 appendix b: 8051 architectural overview ...................... b-1 b.1 introduction .............................................................................................b-1 b.1.1 memory organization .......................................................................b-2 b.1.1.1 program memory ..................................................................... b-2 b.1.1.2 external ram .......................................................................... b-2 b.1.1.3 internal ram ........................................................................... b-2 b.1.2 instruction set ...................................................................................b-3 b.1.3 instruction timing ............................................................................b-9 b.1.4 cpu timing ....................................................................................b-10 b.1.5 stretch memory cycles (wait states) ............................................b-10 b.1.6 dual data pointers ..........................................................................b-11 b.1.7 special function registers ..............................................................b-12 appendix c: 8051 hardware description . ......................c-1 c.1 introduction .............................................................................................c-1 c.2 timers/counters ......................................................................................c-1 c.2.1 803x/805x compatibility ..................................................................c-2 c.2.2 timers 0 and 1 ..................................................................................c-2 c.2.3 mode 0 ..............................................................................................c-2 c.2.4 mode 1 ..............................................................................................c-3 c.2.5 mode 2 ..............................................................................................c-6 c.2.6 mode 3 ..............................................................................................c-7 c.2.7 timer rate control ...........................................................................c-8
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes endpoint 0-7 data buffers cpu access codes: 7b40 out7buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 rw = read or write, 7b80 in7buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 r, r = read-only, 7bc0 out6buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 w, w = write-only 7c00 in6buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 b = both (read & write) 7c40 out5buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7c80 in5buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7cc0 out4buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7d00 in4buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7d40 out3buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7d80 in3buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7dc0 out2buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7e00 in2buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7e40 out1buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7e80 in1buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7ec0 out0buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7f00 in0buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7f40-7f5f (reserved) isochronous data 7f60 out8data endpoint 8 out data d7 d6 d5 d4 d3 d2 d1 d0 7f61 out9data endpoint 9 out data d7 d6 d5 d4 d3 d2 d1 d0 7f62 out10data endpoint 10 out data d7 d6 d5 d4 d3 d2 d1 d0 7f63 out11data endpoint 11 out data d7 d6 d5 d4 d3 d2 d1 d0 7f64 out12data endpoint 12 out data d7 d6 d5 d4 d3 d2 d1 d0 7f65 out13data endpoint 13 out data d7 d6 d5 d4 d3 d2 d1 d0 7f66 out14data endpoint 14 out data d7 d6 d5 d4 d3 d2 d1 d0 7f67 out15data endpoint 15 out data d7 d6 d5 d4 d3 d2 d1 d0 7f68 in8data endpoint 8 in data d7 d6 d5 d4 d3 d2 d1 d0 7f69 in9data endpoint 9 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6a in10data endpoint 10 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6b in11data endpoint 11 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6c in12data endpoint 12 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6d in13data endpoint 13 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6e in14data endpoint 14 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6f in15data endpoint 15 in data d7 d6 d5 d4 d3 d2 d1 d0 ez-usb trm v 1.9 ez-usb registers page 1
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes endpoint 0-7 data buffers cpu access codes: 7b40 out7buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 rw = read or write, 7b80 in7buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 r, r = read-only, 7bc0 out6buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 w, w = write-only 7c00 in6buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 b = both (read & write) 7c40 out5buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7c80 in5buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7cc0 out4buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7d00 in4buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7d40 out3buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7d80 in3buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7dc0 out2buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7e00 in2buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7e40 out1buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7e80 in1buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7ec0 out0buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7f00 in0buf (64 bytes) d7 d6 d5 d4 d3 d2 d1 d0 7f40-7f5f (reserved) isochronous data 7f60 out8data endpoint 8 out data d7 d6 d5 d4 d3 d2 d1 d0 7f61 out9data endpoint 9 out data d7 d6 d5 d4 d3 d2 d1 d0 7f62 out10data endpoint 10 out data d7 d6 d5 d4 d3 d2 d1 d0 7f63 out11data endpoint 11 out data d7 d6 d5 d4 d3 d2 d1 d0 7f64 out12data endpoint 12 out data d7 d6 d5 d4 d3 d2 d1 d0 7f65 out13data endpoint 13 out data d7 d6 d5 d4 d3 d2 d1 d0 7f66 out14data endpoint 14 out data d7 d6 d5 d4 d3 d2 d1 d0 7f67 out15data endpoint 15 out data d7 d6 d5 d4 d3 d2 d1 d0 7f68 in8data endpoint 8 in data d7 d6 d5 d4 d3 d2 d1 d0 7f69 in9data endpoint 9 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6a in10data endpoint 10 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6b in11data endpoint 11 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6c in12data endpoint 12 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6d in13data endpoint 13 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6e in14data endpoint 14 in data d7 d6 d5 d4 d3 d2 d1 d0 7f6f in15data endpoint 15 in data d7 d6 d5 d4 d3 d2 d1 d0 ez-usb trm v 1.9 ez-usb registers page 1
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes isochronous byte counts 7f70 out8bch ep8 out byte count h 0 0 0 0 0 0 d9 d8 7f71 out8bcl ep8 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f72 out9bch ep9 out byte count h 0 0 0 0 0 0 d9 d8 7f73 out9bcl ep9 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f74 out10bch ep10 out byte count h 0 0 0 0 0 0 d9 d8 7f75 out10bcl ep10 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f76 out11bch ep11 out byte count h 0 0 0 0 0 0 d9 d8 7f77 out11bcl ep11 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f78 out12bch ep12 out byte count h 0 0 0 0 0 0 d9 d8 7f79 out12bcl ep12 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f7a out13bch ep13 out byte count h 0 0 0 0 0 0 d9 d8 7f7b out13bcl ep13 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f7c out14bch ep14 out byte count h 0 0 0 0 0 0 d9 d8 7f7d out14bcl ep14 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f7e out15bch ep15 out byte count h 0 0 0 0 0 0 d9 d8 7f7f out15bcl ep15 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f80-7f91 (reserved) cpu registers 7f92 cpucs control & status rv3 rv2 rv1 rv0 0 0 clk24oe 8051res rv[3..0] = chip rev 7f93 portacfg port a configuration rxd1out rxd0out frd fwr cs oe t1out t0out 0=port, 1=alt function 7f94 portbcfg port b configuration t2out int6 int5 int4 txd1 rxd1 t2ex t2 0=port, 1=alt function 7f95 portccfg port c configuration rd wr t1 t0 int1 int0 txd0 rxd0 0=port, 1=alt function input-output port registers 7f96 outa output register a outa7 outa6 outa5 outa4 outa3 outa2 outa1 outa0 7f97 outb output register b outb7 outb6 outb5 outb4 outb3 outb2 outb1 outb0 7f98 outc output register c outc7 outc6 outc5 outc4 outc3 outc2 outc1 outc0 7f99 pinsa port pins a pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 7f9a pinsb port pins b pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 7f9b pinsc port pins c pinc7 pinc6 pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 7f9c oea output enable a oea7 oea6 oea5 oea4 oea3 oea2 oea1 oea0 0=off, 1=drive 7f9d oeb output enable b oeb7 oeb6 oeb5 oeb4 oeb3 oeb2 oeb1 oeb0 0=off, 1=drive 7f9e oec output enable c oec7 oec6 oec5 oec4 oec3 oec2 oec1 oec0 0=off, 1=drive 7f9f uart230 230kbaud support 0 0 0 0 0 0 uart1 uart0 1 = 230kbaud rate isochronous control/status registers 7fa0 isoerr iso out endpoint error iso15err iso14err iso13err iso12err iso11err iso10err iso9err iso8err 7fa1 isoctl isochronous control * * * * ppstat mbz mbz isodisab "mbz" = must be zero 7fa2 zbcout zero byte count bits ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8 7fa3 (reserved) 7fa4 (reserved) i 2 c registers 7fa5 i2cs control & status start stop lastrd id1 id0 berr ack done 7fa6 i2dat data d7 d6 d5 d4 d3 d2 d1 d0 7fa7 i2cmode i2c stop interrupt enable 0 0 0 0 0 0 stopie 0 1=enable int3 on stop ez-usb trm v 1.9 ez-usb registers page 2
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes interrupts 7fa8 ivec interrupt vector 0 iv4 iv3 iv2 iv1 iv0 0 0 7fa9 in07irq epin interrupt request in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir 1=request 7faa out07irq epout interrupt request out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir 1=request 7fab usbirq usb interrupt request * * ibnir uresir suspir sutokir sofir sudavir 1=request 7fac in07ien ep0-7in int enables in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien 1=enabled 7fad out07ien ep0-7out int enables out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien 1=enabled 7fae usbien usb int enables * * ibnie uresie suspie sutokie sofie sudavie 1=enabled 7faf usbbav breakpoint & autovector * * * * break bppulse bpen aven 1=enabled 7fb0 ibnirq ibn interrupt request ep6in ep5in ep4in ep3in ep2in ep1in ep0in 1=request 7fb1 ibnie ibn interrupt enable ep6in ep5in ep4in ep3in ep2in ep1in ep0in 1=enabled 7fb2 bpaddrh breakpoint address h a15 a14 a13 a12 a11 a10 a9 a8 7fb3 bpaddrl breakpoint address l a7 a6 a5 a4 a3 a2 a1 a0 bulk endpoints 0-7 7fb4 ep0cs control & status * * * * outbsy inbsy hsnak ep0stall for ep0in and ep0out 7fb5 in0bc byte count * d6 d5 d4 d3 d2 d1 d0 * this bits are random 7fb6 in1cs control & status * * * * * * in1bsy in1stl at power-on. once 7fb7 in1bc byte count * d6 d5 d4 d3 d2 d1 d0 operational, these bits 7fb8 in2cs control & status * * * * * * in2bsy in2stl read as zeros. 7fb9 in2bc byte count * d6 d5 d4 d3 d2 d1 d0 7fba in3cs control & status * * * * * * in3bsy in3stl 7fbb in3bc byte count * d6 d5 d4 d3 d2 d1 d0 7fbc in4cs control & status * * * * * * in4bsy in4stl 7fbd in4bc byte count * d6 d5 d4 d3 d2 d1 d0 7fbe in5cs control & status * * * * * * in5bsy in5stl 7fbf in5bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc0 in6cs control & status * * * * * * in6bsy in6stl 7fc1 in6bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc2 in7cs control & status * * * * * * in7bsy in7stl 7fc3 in7bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc4 (reserved) 7fc5 out0bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc6 out1cs control & status * * * * * * out1bsy out1stl 7fc7 out1bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc8 out2cs control & status * * * * * * out2bsy out2stl 7fc9 out2bc byte count * d6 d5 d4 d3 d2 d1 d0 7fca out3cs control & status * * * * * * out3bsy out3stl 7fcb out3bc byte count * d6 d5 d4 d3 d2 d1 d0 7fcc out4cs control & status * * * * * * out4bsy out4stl 7fcd ou4tbc byte count * d6 d5 d4 d3 d2 d1 d0 7fce out5cs control & status * * * * * * out5bsy out5stl 7fcf out5bc byte count * d6 d5 d4 d3 d2 d1 d0 7fd0 out6cs control & status * * * * * * out6bsy out6stl 7fd1 out6bc byte count * d6 d5 d4 d3 d2 d1 d0 7fd2 out7cs control & status * * * * * * out7bsy out7stl 7fd3 out7bc byte count * d6 d5 d4 d3 d2 d1 d0 ez-usb trm v 1.9 ez-usb registers page 3
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes global usb registers 7fd4 sudptrh setup data ptr h a15 a14 a13 a12 a11 a10 a9 a8 7fd5 sudptrl setup data ptr l a7 a6 a5 a4 a3 a2 a1 a0 7fd6 usbcs usb control & status wakesrc * * * discon discoe renum sigrsume clear b7 by writing "1" 7fd7 togctl toggle control q s r io 0 ep2 ep1 ep0 7fd8 usbframel frame number l fc7 fc6 fc5 fc4 fc3 fc2 fc1 fc0 7fd9 usbframeh frame number h 0 0 0 0 0 fc10 fc9 fc8 7fda (reserved) 7fdb fnaddr function address 0 fa6 fa5 fa4 fa3 fa2 fa1 fa0 7fdc (reserved) 7fdd usbpair endpoint control isosend0 * pr6out pr4out pr2out pr6in pr4in pr2in prx = 1 to pair ep 7fde in07val input endpoint 0-7 valid in7val in6val in5val in4val in3val in2val in1val 1 val =1 means valid 7fdf out07val output endpoint 0-7 valid out7val out6val out5val out4val out3val out2val out1val 1 val =1 means valid 7fe0 inisoval input ep 8-15 valid in15val in14val in13val in12val in11val in10val in9val in8val val =1 means valid 7fe1 outisoval output ep 8-15 valid out15val out14val out13val out12val out11val out10val out9val out8val val =1 means valid 7fe2 fastxfr fast transfer mode fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 7fe3 autoptrh auto-pointer h a15 a14 a13 a12 a11 a10 a9 a8 7fe4 autoptrl auto-pointer l a7 a6 a5 a4 a3 a2 a1 a0 7fe5 autodata auto pointer data d7 d6 d5 d4 d3 d2 d1 d0 7fe6 (reserved) 7fe7 (reserved) setup data 7fe8 setupdat 8 bytes of setup data d7 d6 d5 d4 d3 d2 d1 d0 isochronous fifo sizes 7ff0 out8addr endpt 8 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff1 out9addr endpt 9 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff2 out10addr endpt 10 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff3 out11addr endpt 11 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff4 out12addr endpt 12 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff5 out13addr endpt 13 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff6 out14addr endpt 14 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff7 out15addr endpt 15 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff8 in8addr endpt 8 in start addr a9 a8 a7 a6 a5 a4 0 0 7ff9 in9addr endpt 9 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffa in19addr endpt 10 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffb in11addr endpt 11 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffc in12addr endpt 12 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffd in13addr endpt 13 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffe in14addr endpt 14 in start addr a9 a8 a7 a6 a5 a4 0 0 7fff in15addr endpt 15 in start addr a9 a8 a7 a6 a5 a4 0 0 ez-usb trm v 1.9 ez-usb registers page 4
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes isochronous byte counts 7f70 out8bch ep8 out byte count h 0 0 0 0 0 0 d9 d8 7f71 out8bcl ep8 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f72 out9bch ep9 out byte count h 0 0 0 0 0 0 d9 d8 7f73 out9bcl ep9 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f74 out10bch ep10 out byte count h 0 0 0 0 0 0 d9 d8 7f75 out10bcl ep10 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f76 out11bch ep11 out byte count h 0 0 0 0 0 0 d9 d8 7f77 out11bcl ep11 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f78 out12bch ep12 out byte count h 0 0 0 0 0 0 d9 d8 7f79 out12bcl ep12 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f7a out13bch ep13 out byte count h 0 0 0 0 0 0 d9 d8 7f7b out13bcl ep13 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f7c out14bch ep14 out byte count h 0 0 0 0 0 0 d9 d8 7f7d out14bcl ep14 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f7e out15bch ep15 out byte count h 0 0 0 0 0 0 d9 d8 7f7f out15bcl ep15 out byte count l d7 d6 d5 d4 d3 d2 d1 d0 7f80-7f91 (reserved) cpu registers 7f92 cpucs control & status rv3 rv2 rv1 rv0 0 0 clk24oe 8051res rv[3..0] = chip rev 7f93 portacfg port a configuration rxd1out rxd0out frd fwr cs oe t1out t0out 0=port, 1=alt function 7f94 portbcfg port b configuration t2out int6 int5 int4 txd1 rxd1 t2ex t2 0=port, 1=alt function 7f95 portccfg port c configuration rd wr t1 t0 int1 int0 txd0 rxd0 0=port, 1=alt function input-output port registers 7f96 outa output register a outa7 outa6 outa5 outa4 outa3 outa2 outa1 outa0 7f97 outb output register b outb7 outb6 outb5 outb4 outb3 outb2 outb1 outb0 7f98 outc output register c outc7 outc6 outc5 outc4 outc3 outc2 outc1 outc0 7f99 pinsa port pins a pina7 pina6 pina5 pina4 pina3 pina2 pina1 pina0 7f9a pinsb port pins b pinb7 pinb6 pinb5 pinb4 pinb3 pinb2 pinb1 pinb0 7f9b pinsc port pins c pinc7 pinc6 pinc5 pinc4 pinc3 pinc2 pinc1 pinc0 7f9c oea output enable a oea7 oea6 oea5 oea4 oea3 oea2 oea1 oea0 0=off, 1=drive 7f9d oeb output enable b oeb7 oeb6 oeb5 oeb4 oeb3 oeb2 oeb1 oeb0 0=off, 1=drive 7f9e oec output enable c oec7 oec6 oec5 oec4 oec3 oec2 oec1 oec0 0=off, 1=drive 7f9f uart230 230kbaud support 0 0 0 0 0 0 uart1 uart0 1 = 230kbaud rate isochronous control/status registers 7fa0 isoerr iso out endpoint error iso15err iso14err iso13err iso12err iso11err iso10err iso9err iso8err 7fa1 isoctl isochronous control * * * * ppstat mbz mbz isodisab "mbz" = must be zero 7fa2 zbcout zero byte count bits ep15 ep14 ep13 ep12 ep11 ep10 ep9 ep8 7fa3 (reserved) 7fa4 (reserved) i 2 c registers 7fa5 i2cs control & status start stop lastrd id1 id0 berr ack done 7fa6 i2dat data d7 d6 d5 d4 d3 d2 d1 d0 7fa7 i2cmode i2c stop interrupt enable 0 0 0 0 0 0 stopie 0 1=enable int3 on stop ez-usb trm v 1.9 ez-usb registers page 2
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes interrupts 7fa8 ivec interrupt vector 0 iv4 iv3 iv2 iv1 iv0 0 0 7fa9 in07irq epin interrupt request in7ir in6ir in5ir in4ir in3ir in2ir in1ir in0ir 1=request 7faa out07irq epout interrupt request out7ir out6ir out5ir out4ir out3ir out2ir out1ir out0ir 1=request 7fab usbirq usb interrupt request * * ibnir uresir suspir sutokir sofir sudavir 1=request 7fac in07ien ep0-7in int enables in7ien in6ien in5ien in4ien in3ien in2ien in1ien in0ien 1=enabled 7fad out07ien ep0-7out int enables out7ien out6ien out5ien out4ien out3ien out2ien out1ien out0ien 1=enabled 7fae usbien usb int enables * * ibnie uresie suspie sutokie sofie sudavie 1=enabled 7faf usbbav breakpoint & autovector * * * * break bppulse bpen aven 1=enabled 7fb0 ibnirq ibn interrupt request ep6in ep5in ep4in ep3in ep2in ep1in ep0in 1=request 7fb1 ibnie ibn interrupt enable ep6in ep5in ep4in ep3in ep2in ep1in ep0in 1=enabled 7fb2 bpaddrh breakpoint address h a15 a14 a13 a12 a11 a10 a9 a8 7fb3 bpaddrl breakpoint address l a7 a6 a5 a4 a3 a2 a1 a0 bulk endpoints 0-7 7fb4 ep0cs control & status * * * * outbsy inbsy hsnak ep0stall for ep0in and ep0out 7fb5 in0bc byte count * d6 d5 d4 d3 d2 d1 d0 * this bits are random 7fb6 in1cs control & status * * * * * * in1bsy in1stl at power-on. once 7fb7 in1bc byte count * d6 d5 d4 d3 d2 d1 d0 operational, these bits 7fb8 in2cs control & status * * * * * * in2bsy in2stl read as zeros. 7fb9 in2bc byte count * d6 d5 d4 d3 d2 d1 d0 7fba in3cs control & status * * * * * * in3bsy in3stl 7fbb in3bc byte count * d6 d5 d4 d3 d2 d1 d0 7fbc in4cs control & status * * * * * * in4bsy in4stl 7fbd in4bc byte count * d6 d5 d4 d3 d2 d1 d0 7fbe in5cs control & status * * * * * * in5bsy in5stl 7fbf in5bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc0 in6cs control & status * * * * * * in6bsy in6stl 7fc1 in6bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc2 in7cs control & status * * * * * * in7bsy in7stl 7fc3 in7bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc4 (reserved) 7fc5 out0bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc6 out1cs control & status * * * * * * out1bsy out1stl 7fc7 out1bc byte count * d6 d5 d4 d3 d2 d1 d0 7fc8 out2cs control & status * * * * * * out2bsy out2stl 7fc9 out2bc byte count * d6 d5 d4 d3 d2 d1 d0 7fca out3cs control & status * * * * * * out3bsy out3stl 7fcb out3bc byte count * d6 d5 d4 d3 d2 d1 d0 7fcc out4cs control & status * * * * * * out4bsy out4stl 7fcd ou4tbc byte count * d6 d5 d4 d3 d2 d1 d0 7fce out5cs control & status * * * * * * out5bsy out5stl 7fcf out5bc byte count * d6 d5 d4 d3 d2 d1 d0 7fd0 out6cs control & status * * * * * * out6bsy out6stl 7fd1 out6bc byte count * d6 d5 d4 d3 d2 d1 d0 7fd2 out7cs control & status * * * * * * out7bsy out7stl 7fd3 out7bc byte count * d6 d5 d4 d3 d2 d1 d0 ez-usb trm v 1.9 ez-usb registers page 3
ez-usb registers addr name description d7 d6 d5 d4 d3 d2 d1 d0 notes global usb registers 7fd4 sudptrh setup data ptr h a15 a14 a13 a12 a11 a10 a9 a8 7fd5 sudptrl setup data ptr l a7 a6 a5 a4 a3 a2 a1 a0 7fd6 usbcs usb control & status wakesrc * * * discon discoe renum sigrsume clear b7 by writing "1" 7fd7 togctl toggle control q s r io 0 ep2 ep1 ep0 7fd8 usbframel frame number l fc7 fc6 fc5 fc4 fc3 fc2 fc1 fc0 7fd9 usbframeh frame number h 0 0 0 0 0 fc10 fc9 fc8 7fda (reserved) 7fdb fnaddr function address 0 fa6 fa5 fa4 fa3 fa2 fa1 fa0 7fdc (reserved) 7fdd usbpair endpoint control isosend0 * pr6out pr4out pr2out pr6in pr4in pr2in prx = 1 to pair ep 7fde in07val input endpoint 0-7 valid in7val in6val in5val in4val in3val in2val in1val 1 val =1 means valid 7fdf out07val output endpoint 0-7 valid out7val out6val out5val out4val out3val out2val out1val 1 val =1 means valid 7fe0 inisoval input ep 8-15 valid in15val in14val in13val in12val in11val in10val in9val in8val val =1 means valid 7fe1 outisoval output ep 8-15 valid out15val out14val out13val out12val out11val out10val out9val out8val val =1 means valid 7fe2 fastxfr fast transfer mode fiso fblk rpol rmod1 rmod0 wpol wmod1 wmod0 7fe3 autoptrh auto-pointer h a15 a14 a13 a12 a11 a10 a9 a8 7fe4 autoptrl auto-pointer l a7 a6 a5 a4 a3 a2 a1 a0 7fe5 autodata auto pointer data d7 d6 d5 d4 d3 d2 d1 d0 7fe6 (reserved) 7fe7 (reserved) setup data 7fe8 setupdat 8 bytes of setup data d7 d6 d5 d4 d3 d2 d1 d0 isochronous fifo sizes 7ff0 out8addr endpt 8 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff1 out9addr endpt 9 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff2 out10addr endpt 10 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff3 out11addr endpt 11 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff4 out12addr endpt 12 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff5 out13addr endpt 13 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff6 out14addr endpt 14 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff7 out15addr endpt 15 out start addr a9 a8 a7 a6 a5 a4 0 0 7ff8 in8addr endpt 8 in start addr a9 a8 a7 a6 a5 a4 0 0 7ff9 in9addr endpt 9 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffa in19addr endpt 10 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffb in11addr endpt 11 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffc in12addr endpt 12 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffd in13addr endpt 13 in start addr a9 a8 a7 a6 a5 a4 0 0 7ffe in14addr endpt 14 in start addr a9 a8 a7 a6 a5 a4 0 0 7fff in15addr endpt 15 in start addr a9 a8 a7 a6 a5 a4 0 0 ez-usb trm v 1.9 ez-usb registers page 4
ii table of contents ez-usb trm v1.9 c.2.8 timer 2 ..............................................................................................c-9 c.2.8.1 timer 2 mode control .............................................................c-9 c.2.8.2 16-bit timer/counter mode ...................................................c-10 c.2.8.3 6-bit timer/counter mode with capture ...............................c-11 c.2.8.4 16-bit timer/counter mode with auto-reload .....................c-12 c.2.8.5 baud rate generator mode ...................................................c-12 c.3 serial interface ......................................................................................c-13 c.3.1 803x/805x compatibility ................................................................c-14 c.3.2 mode 0 ............................................................................................c-14 c.3.3 mode 1 ............................................................................................c-19 c.3.3.1 mode 1 baud rate ..................................................................c-19 c.3.3.2 mode 1 transmit ....................................................................c-22 c.3.3.3 mode 1 receive ......................................................................c-22 c.3.4 mode 2 ............................................................................................c-24 c.3.4.1 mode 2 transmit ....................................................................c-24 c.3.4.2 mode 2 receive ......................................................................c-24 c.3.5 mode 3 ............................................................................................c-26 c.3.6 multiprocessor communications ....................................................c-27 c.3.7 interrupt sfrs .................................................................................c-27 c.4 interrupt processing ..............................................................................c-33 c.4.1 interrupt masking ...........................................................................c-33 c.4.2 interrupt priorities ...........................................................................c-34 c.4.3 interrupt sampling ..........................................................................c-35 c.4.4 interrupt latency .............................................................................c-36 c.4.5 single-step operation .....................................................................c-36 c.5 reset ......................................................................................................c-36 c.6 power saving modes ............................................................................c-36 c.6.1 idle mode ........................................................................................c-36
ez-usb trm v1.9 list of figures iii list of figures figure a-1. comparative timing of 8051 and industry standard 8051 . . . . . . . . . . a-3 figure b-1. 8051 block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-1 figure b-2 internal ram organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-3 figure b-3 cpu timing for single-cycle instruction . . . . . . . . . . . . . . . . . . . . . . b-10 figure c-1. timer 0/1 - modes 0 and 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-3 figure c-2. timer 0/1 - mode 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-6 figure c-3. timer 0 - mode 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-7 figure c-4. timer 2 - timer/counter with capture . . . . . . . . . . . . . . . . . . . . . . . . c-11 figure c-5. timer 2 - timer/counter with auto reload . . . . . . . . . . . . . . . . . . . . c-12 figure c-6. timer 2 - baud rate generator mode . . . . . . . . . . . . . . . . . . . . . . . . . c-13 figure c-7. serial port mode 0 receive timing - low speed operation . . . . . . . c-17 figure c-8. serial port mode 0 receive timing - high speed operation . . . . . . . c-17 figure c-9. serial port mode 0 transmit timing - low speed operation . . . . . . c-18 figure c-10. serial port mode 0 transmit timing - high speed operation . . . . . . c-18 figure c-11. serial port 0 mode 1 transmit timing . . . . . . . . . . . . . . . . . . . . . . . . c-23 figure c-12. serial port 0 mode 1 receive timing . . . . . . . . . . . . . . . . . . . . . . . . . c-23 figure c-13. serial port 0 mode 2 transmit timing . . . . . . . . . . . . . . . . . . . . . . . . c-25 figure c-14. serial port 0 mode 2 receive timing . . . . . . . . . . . . . . . . . . . . . . . . . c-25 figure c-15. serial port 0 mode 3 transmit timing . . . . . . . . . . . . . . . . . . . . . . . . c-26 figure c-16. serial port 0 mode 3 receive timing . . . . . . . . . . . . . . . . . . . . . . . . . c-26
iv ez-usb trm v1.9
v list of tables ez-usb trm v1.9 list of tables table a-1. feature summary of 8051 core and common 803x/805x configurations a-4 table b-1. legend for instruction set table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-4 table b-2. 8051 instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-5 table b-3. data memory stretch values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-11 table b-4. special function registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-13 table b-5. special function register reset values . . . . . . . . . . . . . . . . . . . . . . . . . b-14 table b-6. psw register - sfr d0h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . b-16 table c-1. timer/counter implementation comparison . . . . . . . . . . . . . . . . . . . . . . c-2 table c-2. tmod register - sfr 89h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-4 table c-3. tcon register - srf 88h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-5 table c-4. ckcon register - srf 8eh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-8 table c-5. timer 2 mode control summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-9 table c-6. t2con register - sfr c8h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-10 table c-7. serial port modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-14 table c-8. scon0 register - sfr 98h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-15 table c-9. scon1 register - sfr c0h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-16 table c-10. timer 1 reload values for common serial port mode 1 baud rates . c-20 table c-11. timer 2 reload values for common serial port mode 1 baud rates . . c-21 table c-12. ie register - sfr a8h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-28 table c-13. ip register - sfr b8h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-29 table c-14. exif register - sfr 91h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-30 table c-15. eicon register - sfr d8h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-31 table c-16. eie register - sfr e8h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-32 table c-17. eip register - sfr f8h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-33 table c-18. interrupt natural vectors and priorities . . . . . . . . . . . . . . . . . . . . . . . . . c-34 table c-19. interrupt flags, enables, and priority control . . . . . . . . . . . . . . . . . . . . c-35 table c-20. pcon register - sfr 87h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c-37
ez-usb trm v1.9 appendix a: 8051 introduction a - 1 appendix a: 8051 introduction a.1 introduction the ez-usb contains an 8051 core that is binary compatible with the industry standard 8051 instruction set. this appendix provides an overview of the 8051 core features. the topics are: ? new 8051 features ? performance overview ? software compatibility ? 803x/805x feature comparison ? 8051/ds80c320 differences a.2 8051 features the 8051 core provides the following design features and enhancements to the standard 8051 micro-controller: ? compatible with industry standard 803x/805x: - standard 8051 instruction set - two full-duplex serial ports - three timers ? high speed architecture: - 4 clocks/instruction cycle - 2.5x average improvement in instruction execution time over the standard 8051 - runs dc to 25-mhz clock - wasted bus cycles eliminated - dual data pointers ? 256 bytes internal data ram ? high-speed external memory interface with 16-bit address bus ? variable length movx to access fast/slow ram peripherals ? fully static synchronous design ? supports industry standard compilers, assemblers, emulators, and rom monitors
a - 2 appendix a: 8051 introduction ez-usb trm v1.9 a.3 performance overview the 8051 core has been designed to offer increased performance by executing instructions in a 4-clock bus cycle, as opposed to the 12-clock bus cycle in the standard 8051 (see figure a-1.). the shortened bus timing improves the instruction execution rate for most instructions by a factor of three over the standard 8051 architectures. some instructions require a different number of instruction cycles on the 8051 core than they do on the standard 8051. in the standard 8051, all instructions except for mul and div take one or two instruction cycles to complete. in the 8051 core, instructions can take between one and five instruction cycles to complete. the average speed improvement for the entire instruction set is approximately 2.5x, calculated as follows: number of opcodes speed improvement 150 3.0x 51 1.5x 43 2.0x 22.4x total: 255 average: 2.5x note: comparison is for 8051 and standard 8051 running at the same clock frequency.
ez-usb trm v1.9 appendix a: 8051 introduction a - 3 a.4 software compatibility the 8051 core is object code compatible with the industry standard 8051 micro-controller. that is, object code compiled with an industry standard 8051 compiler or assembler will execute on the 8051 core and will be functionally equivalent. however, because the 8051 core uses a different instruction timing than the standard 8051, existing code with timing loops may require modification. the instruction set in table b-2 on page b-5 lists the number of instruction cycles required to perform each instruction on the 8051 core. the 8051 instruction cycle timing and number of instruction cycles required for each instruction are compatible with the dallas semiconductor ds80c320. figure a-1. comparative timing of 8051 and industry standard 8051 psen# ale xtal1 ad0-ad7 psen# ale port2 8051 timing standard 8051 timing port2 single byte single cycle instruction single byte single cycle instruction ad0-ad7 4 12
a - 4 appendix a: 8051 introduction ez-usb trm v1.9 a.5 803x/805x feature comparison table a-1. provides a feature-by-feature comparison of the 8051 core and several common 803x/805x configurations. table a-1. feature summary of 8051 core and common 803x/805x configurations feature intel dallas ds80c320 anchor 8051 8031 8051 80c32 80c52 clocks per instruction cycle 12 12 12 12 4 4 program / data memory - 4 kb rom -8kb rom -8kram internal ram 128 bytes 128 bytes 256 bytes 256 bytes 256 bytes 256 bytes datapointers 1111 2 2 serialports 1111 2 2 16-bittimers 2233 3 3 interrupt sources (total of int. and ext.) 5566 13 13 stretchmemorycycles nononono yes yes
ez-usb trm v1.9 appendix a: 8051 introduction a - 5 a.6 8051 core/ds80c320 differences the 8051 core is similar to the ds80c320 in terms of hardware features and instruction cycle timing. however, there are some important differences between the 8051 core and the ds80c320. a.6.1 serial ports the 8051 core does not implement serial port framing error detection and does not implement slave address comparison for multiprocessor communications. therefore, the 8051 core also does not implement the following sfrs: saddr0, saddr1, saden0, and saden1. a.6.2 timer 2 the 8051 core does not implement timer 2 downcounting mode or the downcount enable bit (tmod2, bit 0). also, the 8051 core does not implement timer 2 output enable (t2oe) bit (tmod2, bit 1). therefore, the tmod2 sfr is also not implemented in the 8051 core. also, the 8051 core timer 2 overflow output is active for one clock cycle. in the ds80c320, the timer 2 overflow output is a square wave with a 50% duty cycle. a.6.3 timed access protection the 8051 core does not implement timed access protection and therefore, does not implement the ta sfr. a.6.4 watchdog timer the ez-usb/8051 does not implement a watchdog timer.
a - 6 appendix a: 8051 introduction ez-usb trm v1.9
ez-usb trm v1.9 appendix b: 8051 architectural overview b - 1 appendix b: 8051 architectural overview b.1 introduction this appendix provides a technical overview and description of the 8051 core architecture. figure b-1. 8051 block diagram 8051_cpu 8051_intr_0 8051_ram_128 8051_timer (lower 128 byte ram) timers 0 and 1 8051_timer2 8051_serial serial port 0 timer 2 interrupt unit interrupts a15-a0 port_control 8051 (0..7fh direct/indirect) pc4/to, pc5/t1 pa0/t0_out, pc1/txd0 pa6/rxd0out pc0/rxd0in pb0/t2 pb1/t2ex 8051_biu 8051_op_decoder 8051_ram_128 8051_alu 8051_control (80..ffh indirect) clk24 pb7/t2out 8051_ main_regs 8051_intr_1 or 8051_serial serial port 1 pb3/txd1 pa7/rxd1out pb2/rxd1in pa1/t0_out d7 - d0 reset#
b - 2 appendix b: 8051 architectural overview ez-usb trm v1.9 b.1.1 memory organization memory organization in the 8051 core is similar to that of the industry standard 8051. there are three distinct memory areas: program memory (rom), data memory (external ram), and registers (internal ram). b.1.1.1 program memory the ez-usb provides 8k of data that is mapped as both program and data memory at addresses 0x0000-0x1b3f. in addition, the bulk endpoint buffers may be used as external data memory if they are not used as endpoint buffers. see chapter 3, "ez-usb memory" for more details. b.1.1.2 external ram the ez-usb chip has dedicated address and data pins, so port 2 and port 0 are not used to access the memory bus. as shown in chapter 3, "ez-usb memory", the ez-usb is expandable to over 100k of external program and data memory. b.1.1.3 internal ram the internal ram (figure b-2) consists of: ? 128 bytes of registers and scratch pad memory accessible through direct or indirect addressing (addresses 00hC7fh). ? a 128 register space for special function registers (sfrs) accessible through direct addressing (addresses 80hCffh). ? upper 128 bytes of scratch pad memory accessible through indirect addressing (addresses 80hCffh). although the sfr space and the upper 128 bytes of ram share the same address range, the actual address space is separate and is differentiated by the type of addressing. direct addressing accesses the sfrs, and indirect addressing accesses the upper 128 bytes of ram. the lower 128 bytes are organized as shown in figure b-2. the lower 32 bytes (0x00-0xif) form four banks of eight registers (r0Cr7). two bits on the program status word (psw) select which bank is in use. the next 16 bytes (0x20 - 0x2f) form a block of bit-addressable memory space at bit addresses 0h-7fh. all of the bytes in the lower 128 bytes are accessible through direct or indirect addressing. the sfrs occupy addresses 80hCffh and are only accessible through direct addressing. most sfrs are reserved for specific functions as described in the special function registers on page b-12. sfr addresses ending in 0h or 8h are bit-addressable.
ez-usb v1.9 appendix b: 8051 architectural overview b - 3 b.1.2 instruction set all 8051 instructions are binary code compatible and perform the same functions as they do with the industry standard 8051. the effects of these instructions on bits, flags, and other status functions is identical to the industry standard 8051. however, the timing of the instructions is different, both in terms of number of clock cycles per instruction cycle and timing within the instruction cycle. figure b-2 lists the 8051 instruction set and the number of instruction cycles required to complete each instruction. table b-1. defines the symbols and mnemonics used in table b-2. figure b-2 internal ram organization 00h ffh 7fh 80h lower 128 bytes upper 128 bytes (optional) sfr space ffh 80h lower 128 bytes 00h bank 0 07h 08h bank 1 0fh 10h bank 2 bank 3 17h 18h 1fh 20h 2fh 30h 7fh 00 07 78 7f . . . . . . . . . bit-addressable registers direct ram direct or indirect addressing indirect addressing only direct addressing only 00 01 10 11 bank select (psw bits 4,3)
b - 4 appendix b: 8051 architectural overview ez-usb trm v1.9 table b-1. legend for instruction set table symbol function a accumulator rn register r7Cr0 direct internal register address @ri internal register pointed to by r0 or r1 (except movx) rel twos complement offset byte bit direct bit address #data 8-bit constant #data 16 16-bit constant addr 16 16-bit destination address addr 11 11-bit destination address
ez-usb v1.9 appendix b: 8051 architectural overview b - 5 table b-2. 8051 instruction set mnemonic description byte instr. cycles hex code arithmetic add a, rn add register to a 1 1 28-2f add a, direct add direct byte to a 2 2 25 add a, @ri add data memory to a 1 1 26-27 addc a, #data add immediate to a 2 2 24 addc a, rn add register to a with carry 1 1 38-3f addc a, direct add direct byte to a with carry 2 2 35 addc a, @ri add data memory to a with carry 1 1 36-37 addc a, #data add immediate to a with carry 2 2 34 subb a, rn subtract register from a with borrow 1 1 98-9f subb a, direct subtract direct byte from a with borrow 2 2 95 subb a, @ri subtract data memory from a with borrow 1 1 96-97 subb a, #data subtract immediate from a with borrow 2 2 94 inc a increment a 1 1 04 inc rn increment register 1 1 08-0f inc direct increment direct byte 2 2 05 inc @ ri increment data memory 1 1 06-07 dec a decrement a 1 1 14 dec rn decrement register 1 1 18-1f dec direct decrement direct byte 2 2 15 dec @ri decrement data memory 1 1 16-17 inc dptr increment data pointer 1 3 a3 mul ab multiply a by b 1 5 a4 div ab divide a by b 1 5 84 da a decimal adjust a 1 1 d4
b - 6 appendix b: 8051 architectural overview ez-usb trm v1.9 logical anl, rn and register to a 1 1 58-5f anl a, direct and direct byte to a 2 2 55 anl a, @ri and data memory to a 1 1 56-57 anl a, #data and immediate to a 2 2 54 anl direct, a and a to direct byte 2 2 52 anl direct, #data and immediate data to direct byte 3 3 53 orl a, rn or register to a 1 1 48-4f orl a, direct or direct byte to a 2 2 45 orl a, @ri or data memory to a 1 1 46-47 orl a, #data or immediate to a 2 2 44 orl direct, a or a to direct byte 2 2 42 orl direct, #data or immediate data to direct byte 3 3 43 xorl a, rn exclusive-or register to a 1 1 68-6f xorl a, direct exclusive-or direct byte to a 2 2 65 xorl a, @ri exclusive-or data memory to a 1 1 66-67 xorl a, #data exclusive-or immediate to a 2 2 64 xorl direct, a exclusive-or a to direct byte 2 2 62 xorl direct, #data exclusive-or immediate data to direct byte 3 3 63 clr a clear a 1 1 e4 cpl a complement a 1 1 f4 swap a swap nibbles of a 1 1 c4 rl a rotate a left 1 1 23 rlc a rotate a left through carry 1 1 33 rra rotate a right 1 1 03 rrc a rotate a right through carry 1 1 13 table b-2. 8051 instruction set mnemonic description byte instr. cycles hex code
ez-usb v1.9 appendix b: 8051 architectural overview b - 7 data transfer mov a, rn move register to a 1 1 e8-ef mov a, direct move direct byte to a 2 2 e5 mov a, @ri move data memory to a 1 1 e6-e7 mov a, #data move immediate to a 2 2 74 mov rn, a move a to register 1 1 f8-ff mov rn, direct move direct byte to register 2 2 a8-af mov rn, #data move immediate to register 2 2 78-7f mov direct, a move a to direct byte 2 2 f5 mov direct, rn move register to direct byte 2 2 88-8f mov direct, direct move direct byte to direct byte 3 3 85 mov direct, @ri move data memory to direct byte 2 2 86-87 mov direct, #data move immediate to direct byte 3 3 75 mov @ri, a mov a to data memory 1 1 f6-f7 mov @ri, direct move direct byte to data memory 2 2 a6-a7 mov @ri, #data move immediate to data memory 2 2 76-77 mov dptr, #data move immediate to data pointer 3 3 90 movc a, @a+dptr move code byte relative dptr to a 1 3 93 movc a, @a+pc move code byte relative pc to a 1 3 83 movx a, @ri move external data (a8) to a 1 2-9* e2-e3 movx a, @dptr move external data (a16) to a 1 2-9* e0 movx @ri, a move a to external data (a8) 1 2-9* f2-f3 movx @dptr, a move a to external data (a16) 1 2-9* f0 push direct push direct byte onto stack 2 2 c0 pop direct pop direct byte from stack 2 2 d0 xch a, rn exchange a and register 1 1 c8-cf xch a, direct exchange a and direct byte 2 2 c5 table b-2. 8051 instruction set mnemonic description byte instr. cycles hex code
b - 8 appendix b: 8051 architectural overview ez-usb trm v1.9 xcha,@ri exchangeaanddatamemory 1 1 c6-c7 xchd a, @ri exchange a and data memory nibble 1 1 d6-d7 * number of cycles is user-selectable. see stretch memory cycles (wait states) on page b-10. boolean clr c clear carry 1 1 c3 clr bit clear direct bit 2 2 c2 setb c set carry 1 1 d3 setb bit set direct bit 2 2 d2 cpl c complement carry 1 1 b3 cpl bit complement direct bit 2 2 b2 anl c, bit and direct bit to carry 2 2 82 anl c, /bit and direct bit inverse to carry 2 2 b0 orl c, bit or direct bit to carry 2 2 72 orl c, /bit or direct bit inverse to carry 2 2 a0 mov c, bit move direct bit to carry 2 2 a2 mov bit, c move carry to direct bit 2 2 92 branching acall addr 11 absolute call to subroutine 2 3 11-f1 lcall addr 16 long call to subroutine 3 4 12 ret return from subroutine 1 4 22 reti return from interrupt 1 4 32 ajmp addr 11 absolute jump unconditional 2 3 01-e1 ljmp addr 16 long jump unconditional 3 4 02 sjmp rel short jump (relative address) 2 3 80 jcrel jumponcarry=1 2 3 40 jnc rel jump on carry = 0 2 3 50 jb bit, rel jump on direct bit = 1 3 4 20 table b-2. 8051 instruction set mnemonic description byte instr. cycles hex code
ez-usb v1.9 appendix b: 8051 architectural overview b - 9 b.1.3 instruction timing instruction cycles in the 8051 core are 4 clock cycles in length, as opposed to the 12 clock cycles per instruction cycle in the standard 8051. this translates to a 3x improvement in execution time for most instructions. some instructions require a different number of instruction cycles on the 8051 core than they do on the standard 8051. in the standard 8051, all instructions except for mul and div take one or two instruction cycles to complete. in the 8051 core, instructions can take between one and five instruction cycles to complete. for example, in the standard 8051, the instructions movx a, @dptr and mov direct, direct each take 2 instruction cycles (24 clock cycles) to execute. in the 8051 core, movx a, @dptr takes two instruction cycles (8 clock cycles) and mov direct, direct takes three instruction cycles (12 clock cycles). both instructions execute faster on the 8051 core than they do on the standard 8051, but require different numbers of clock cycles. for timing of real-time events, use the numbers of instruction cycles from table b-1. to calculate the timing of software loops. the bytes column indicates the number of memory jnb bit, rel jump on direct bit = 0 3 4 30 jbc bit, rel jump on direct bit = 1 and clear 3 4 10 jmp @ a+dptr jump indirect relative dptr 1 3 73 jz rel jump on accumulator = 0 2 3 60 jnz rel jump on accumulator /= 0 2 3 70 cjne a, direct, rel compare a, direct jne relative 3 4 b5 cjne a, #d, rel compare a, immediate jne relative 3 4 b4 cjne rn, #d, rel compare reg, immediate jne relative 3 4 b8-bf cjne @ ri, #d, rel compare ind, immediate jne relative 3 4 b6-b7 djnz rn, rel decrement register, jnz relative 2 3 d8-df djnz direct, rel decrement direct byte, jnz relative 3 4 d5 miscellaneous nop no operation 1 1 00 there is an additional reserved opcode (a5) that performs the same function as nop. all mnemonics are copyrighted. intel corporation 1980. table b-2. 8051 instruction set mnemonic description byte instr. cycles hex code
b - 10 appendix b: 8051 architectural overview ez-usb trm v1.9 accesses (bytes) needed to execute the instruction. in most cases, the number of bytes is equal to the number of instruction cycles required to complete the instruction. however, as indicated, there are some instructions (for example, div and mul ) that require a greater number of instruction cycles than memory accesses. by default, the 8051 core timer/counters run at 12 clock cycles per increment so that timer- based events have the same timing as with the standard 8051. the timers can also be configured to run at 4 clock cycles per increment to take advantage of the higher speed of the 8051 core. b.1.4 cpu timing as previously stated, an 8051 core instruction cycle consists of 4 clk24 cycles. each clk24 cycle forms a cpu cycle. therefore, an instruction cycle consists of 4 cpu cycles: c1, c2, c3, and c4, as illustrated in figure b-3. various events occur in each cpu cycle, depending on the type of instruction being executed. the labels c1, c2, c3, and c4 in timing descriptions refer to the 4 cpu cycles within a particular instruction cycle. the execution for instruction n is performed during the fetch of instruction n +1. data writes occur during fetch of instruction n +2. the level sensitive interrupts are sampled with the rising edge of clk24 at the end of c3. b.1.5 stretch memory cycles (wait states) the stretch memory cycle feature enables application software to adjust the speed of data memory access. the 8051 core can execute the movx instruction in as few as 2 instruction cycles. however, it is sometimes desirable to stretch this value; for example to access slow memory or slow memory-mapped peripherals such as uarts or lcds. the three lsbs of the clock control register (at sfr location 8eh) control the stretch value. you can use stretch values between zero and seven. a stretch value of zero adds zero instruction cycles, resulting in movx instructions executing in two instruction cycles. a stretch value of seven adds seven instruction cycles, resulting in movx instructions executing in nine instruction cycles. the stretch value can be changed dynamically under program control. figure b-3 cpu timing for single-cycle instruction clk24 instruction cycle cpu cycle n + 1 n + 2 c1 c2 c3 c4 c1 c2 c3 c4 c1
ez-usb v1.9 appendix b: 8051 architectural overview b - 11 by default, the stretch value resets to one (three cycle movx ). for full-speed data memory access, the software must set the stretch value to zero. the stretch value affects only data memory access (not program memory). the stretch value affects the width of the read/write strobe and all related timing. using a higher stretch value results in a wider read/write strobe, which allows the memory or peripheral more time to respond. table b-3. lists the data memory access speeds for stretch values zero through seven. md2C0 are the three lsbs of the clock control register (ckcon.2C0). b.1.6 dual data pointers the 8051core employs dual data pointers to accelerate data memory block moves. the standard 8051 data pointer (dptr) is a 16-bit value used to address external data ram or peripherals. the 8051 maintains the standard data pointer as dptr0 at sfr locations 82h (dpl0) and 83h (dph0). it is not necessary to modify existing code to use dptr0. the 8051 core adds a second data pointer (dptr1) at sfr locations 84h (dpl1) and 85h (dph1). the sel bit in the dptr select register, dps (sfr 86h), selects the active pointer. when sel = 0, instructions that use the dptr will use dpl0 and dph0. when sel = 1, instructions that use the dptr will use dpl1 and dph1. sel is the bit 0 of sfr location 86h. no other bits of sfr location 86h are used. table b-3. data memory stretch values md2 md1 md0 memory cycles read/write strobe width (clocks) strobe width @ 24mhz 000 2 2 83.3ns 0 0 1 3 (default) 4 166.7 ns 0 1 0 4 8 333.3 ns 0 1 1 5 12 500 ns 1 0 0 6 16 666.7 ns 1 0 1 7 20 833.3 ns 1 1 0 8 24 1000 ns 1 1 1 9 28 1166.7 ns
b - 12 appendix b: 8051 architectural overview ez-usb trm v1.9 all dptr-related instructions use the currently selected data pointer. to switch the active pointer, toggle the sel bit. the fastest way to do so is to use the increment instruction ( inc dps ). this requires only one instruction to switch from a source address to a destination address, saving application code from having to save source and destination addresses when doing a block move. using dual data pointers provides significantly increased efficiency when moving large blocks of data. the sfr locations related to the dual data pointers are: 82h dpl0 dptr0 low byte 83h dph0 dptr0 high byte 84h dpl1 dptr1 low byte 85h dph1 dptr1 high byte 86h dps dptr select (bit 0) b.1.7 special function registers the special function registers (sfrs) control several of the features of the 8051. most of the 8051 core sfrs are identical to the standard 8051 sfrs. however, there are additional sfrs that control features that are not available in the standard 8051. table b-4. lists the 8051 core sfrs and indicates which sfrs are not included in the standard 8051 sfr space. in table b-5., sfr bit positions that contain a 0 or a 1 cannot be written to and, when read, always return the value shown (0 or 1). sfr bit positions that contain - are available but not used. table b-5. lists the reset values for the sfrs. the following sfrs are related to cpu operation and program execution: 81h sp stack pointer d0h psw program status word () e0h acc accumulator register f0h b b register table b-6. lists the functions of the bits in the psw sfr. detailed descriptions of the remaining sfrs appear with the associated hardware descriptions in appendix c of this databook.
ez-usb v1.9 appendix b: 8051 architectural overview b - 13 table b-4. special function registers register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 addr sp 81h dpl0 82h dph0 83h dpl1 (1) 84h dph1 (1) 85h dps (1) 0000 000sel86h pcon smod0 - 1 1 gf1 gf0 stop idle 87h tcon tf1 tr1 tf0 tr0 ie1 it1 ie0 it0 88h tmod gate c/t m1 m0 gate c/t m1 m0 89h tl0 8ah tl1 8bh th0 8ch th1 8dh ckcon (1) - - t2m t1m t0m md2 md1 md0 8eh spc_fnc (1) 0000 000wrs8fh exif (1) ie5ie4i2cintusbint100091h mpage (1) 92h scon0 sm0_0 sm1_0 sm2_0 ren_0 tb8_0 rb8_0 ti_0 ri_0 98h sbuf0 99h ie ea es1 et2 es0 et1 ex1 et0 ex0 a8h ip 1 ps1 pt2 ps0 pt1 px1 pt0 px0 b8h scon1 (1) sm0_1 sm1_1 sm2_1 ren_1 tb8_1 rb8_1 ti_1 ri_1 c0h sbuf1 (1) c1h t2con tf2 exf2 rclk tclk exen2 tr2 c/t2 cp/rl2 c8h rcap2l cah rcap2h cbh tl2 cch
b - 14 appendix b: 8051 architectural overview ez-usb trm v1.9 th2 cdh psw cy ac f0 rs1 rs0 ov f1 p d0h eicon (1) smod1 1 eresi resi int6 0 0 0 d8h acc e0h eie (1) 1 1 1 ewdi ex5 ex4 ei2c eusb e8h b f0h eip (1) 1 1 1 px6 px5 px4 pi2c pusb f8h (1) not part of standard 8051 architecture. table b-5. special function register reset values register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 addr sp 0000011181h dpl0 0000000082h dph0 0000000083h dpl1 (1) 0000000084h dph1 (1) 0000000085h dps (1) 0000000086h pcon 0011000087h tcon 0000000088h tmod 0000000089h tl0 000000008ah tl1 000000008bh th0 000000008ch th1 000000008dh ckcon (1) 000000018eh spc_fnc (1) 000000008fh exif (1) 0000100091h table b-4. special function registers register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 addr
ez-usb v1.9 appendix b: 8051 architectural overview b - 15 mpage (1) 0000000092h scon0 0000000098h sbuf0 0000000099h ie 00000000a8h ip 10000000b8h scon1 (1) 00000000c0h sbuf1 (1) 00000000c1h t2con 00000000c8h rcap2l 00000000cah rcap2h 00000000cbh tl2 00000000cch th2 00000000cdh psw 00000000d0h eicon (1) 01000000d8h acc 00000000e0h eie (1) 11100000e8h b 00000000f0h eip (1) 11100000f8h (1) not part of standard 8051 architecture. table b-5. special function register reset values register bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 addr
b - 16 appendix b: 8051 architectural overview ez-usb trm v1.9 table b-6. psw register - sfr d0h bit function psw.7 cy - carry flag. this is the unsigned carry bit. the cy flag is set when an arithmetic operation results in a carry from bit 7 to bit 8, and cleared otherwise. in other words, it acts as a virtual bit 8. the cy flag is cleared on multiplication and division. psw.6 ac - auxiliary carry flag. set to 1 when the last arithmetic operation resulted in a carry into (during addition) or borrow from (during subtraction) the high order nibble, otherwise cleared to 0 by all arithmetic operations. psw.5 f0 - user flag 0. bit-addressable, general purpose flag for software control. psw.4 rs1 - register bank select bit 1. used with rs0 to select a register bank in internal ram. psw.3 rs0 - register bank select bit 0, decoded as: rs1 rs0 banks selected 0 0 register bank 0, addresses 00h-07h 0 1 register bank 1, addresses 08h-0fh 1 0 register bank 2, addresses 10h-17h 1 1 register bank 3, addresses 18h-1fh psw.2 ov - overflow flag. this is the signed carry bit. the ov flag is set when a positive sum exceeds 7fh, or a negative sum (in twos compliment notation) exceeds 80h. on a multiply, if ov = 1, the result of the multiply is greater than ffh. on a divide, ov=1onadivideby0. psw.1 f1 - user flag 1. bit-addressable, general purpose flag for software control. psw.0 p - parity flag. set to 1 when the modulo-2 sum of the 8 bits in theaccumulatoris1(oddparity),clearedto0onevenparity.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 1 appendix c: 8051 hardware description c.1 introduction this chapter provides technical data about the 8051 core hardware operation and timing. the topics are: ? timers/counters ? serial interface ? interrupts ? reset ? power saving modes c.2 timers/counters the 8051 core includes three timer/counters (timer 0, timer 1, and timer 2). each timer/ counter can operate as either a timer with a clock rate based on the clk24 pin, or as an event counter clocked by the t0 pin (timer 0), t1 pin (timer 1), or the t2 pin (timer 2). each timer/counter consists of a 16-bit register that is accessible to software as two sfrs: ? timer 0 - tl0 and th0 ? timer 1 - tl1 and th1 ? timer 2 - tl2 and th2
c - 2 appendix c: 8051 hardware description ez-usb trm v1.9 c.2.1 803x/805x compatibility the implementation of the timers/counters is similar to that of the dallas semiconductor ds80c320. table c-1. summarizes the differences in timer/counter implementation between the intel 8051, the dallas semiconductor ds80c320, and the 8051 core. c.2.2 timers 0 and 1 timers 0 and 1 each operate in four modes, as controlled through the tmod sfr (table c-2.) and the tcon sfr (table c-3.). the four modes are: ? 13-bit timer/counter (mode 0) ? 16-bit timer/counter (mode 1) ? 8-bit counter with auto-reload (mode 2) ? two 8-bit counters (mode 3, timer 0 only) c.2.3 mode 0 mode 0 operation, illustrated in figure c-1., is the same for timer 0 and timer 1. in mode 0, the timer is configured as a 13-bit counter that uses bits 0-4 of tl0 (or tl1) and all 8 bits of th0 (or th1). the timer enable bit (tr0/tr1) in the tcon sfr starts the timer. the c/t bit selects the timer/counter clock source, clk24 or the t0/t1 pins . the timer counts transitions from the selected source as long as the gate bit is 0, or the gate bit is 1 and the corresponding interrupt pin (int0# or int1#) is 1. when the 13-bit count increments from 1fffh (all ones), the counter rolls over to all zeros, the tf0 (or tf1) bit is set in the tcon sfr, and the t0out (or t1out) pin goes high for one clock cycle. table c-1. timer/counter implementation comparison feature intel 8051 dallas ds80c320 8051 number of timers 2 3 3 timer 0/1 overflow available as output signals not implemented not implemented t0out, t1out (one clk24 pulse) timer 2 output enable n/a implemented not implemented timer 2 downcount enable n/a implemented not implemented timer 2 overflow available as output signal n/a implemented t2out (one clk24 pulse)
ez-usb trm v1.9 appendix c: 8051 hardware description c - 3 the upper 3 bits of tl0 (or tl1) are indeterminate in mode 0 and must be masked when the software evaluates the register. c.2.4 mode 1 mode 1 operation is the same for timer 0 and timer 1. in mode 1, the timer is configured as a 16-bit counter. as illustrated in figure c-1., all 8 bits of the lsb register (tl0 or tl1) are used. the counter rolls over to all zeros when the count increments from ffffh. otherwise, mode 1 operation is the same as mode 0. figure c-1. timer 0/1 - modes 0 and 1 tl0 (or tl1) 0 7 4 divide by 12 divide by 4 clk24 t0 (or t1) pin tr0 (or tr1) gate int0# pin (or int1#) 7 0 tf0 (or tf1) int th0 (or th1) t0m (or t1m) mode 0 mode 1 0 1 0 1 to serial port (timer 1 only) clk c/ t
c - 4 appendix c: 8051 hardware description ez-usb trm v1.9 table c-2. tmod register - sfr 89h bit function tmod.7 gate - timer 1 gate control. when gate = 1, timer 1 will clock only when int1# = 1 and tr1 (tcon.6) = 1. when gate = 0, timer 1 will clock only when tr1 = 1, regardless of the state of int1#. tmod.6 - counter/timer select. when = 0, timer 1 is clocked by clk24/4 or clk24/12, depending on the state of t1m (ckcon.4). when = 1, timer 1 is clocked by the t1 pin. tmod.5 m1 - timer 1 mode select bit 1. tmod.4 m0 - timer 1 mode select bit 0, decoded as: m1 m0 mode 0 0 mode 0 : 13-bit counter 0 1 mode 1 : 16-bit counter 1 0 mode 2 : 8-bit counter with auto-reload 1 1 mode 3 : timer 1 stopped tmod.3 gate - timer 0 gate control, when gate = 1, timer 0 will clockonlywhenint0=1andtr0(tcon.4)=1.when gate = 0, timer 0 will clock only when tr0 = 1, regardless of the state of int0. tmod.2 - counter/timer select. when = 0, timer 0 is clocked by clk24/4 or clk24/12, depending on the state of t0m (ckcon.3). when = 1, timer 0 is clocked by the t0 pin. tmod.1 m1 - timer 0 mode select bit 1. tmod.0 m0 - timer 0 mode select bit 0, decoded as: m1 m0 mode 0 0 mode 0 : 13-bit counter 0 1 mode 1 : 16-bit counter 1 0 mode 2 : 8-bit counter with auto-reload 1 1 mode 3 : two 8-bit counters c/ t c/ t c/ t c/ t c/ t c/ t
ez-usb trm v1.9 appendix c: 8051 hardware description c - 5 table c-3. tcon register - srf 88h bit function tcon.7 tf1 - timer 1 overflow flag. set to 1 when the timer 1 count overflows and cleared when the processor vectors to the interrupt service routine. tcon.6 tr1 - timer 1 run control. set to 1 to enable counting on timer 1. tcon.5 tf0 - timer 0 overflow flag. set to 1 when the timer 0 count overflows and cleared when the processor vectors to the interrupt service routine. tcon.4 tr0 - timer 0 run control. set to 1 to enable counting on timer 0. tcon.3 ie1 - interrupt 1 edge detect. if external interrupt 1 is configured to be edge-sensitive (it1 = 1), ie1 is set by hardware when a negative edge is detected on the int1 pin and is automatically cleared when the cpu vectors to the corresponding interrupt service routine. in this case, ie1 can also be cleared by software. if external interrupt 1 is configured to be level-sensitive (it1 = 0), ie1 is set when the int1# pin is 0 and cleared when the int1# pin is 1. in level- sensitive mode, software cannot write to ie1. tcon.2 it1 - interrupt 1 type select. int1 is detected on falling edge when it1 = 1; int1 is detected as a low level when it1 = 0. tcon.1 ie0 - interrupt 0 edge detect. if external interrupt 0 is configured to be edge-sensitive (it0 = 1), ie0 is set by hardware when a negative edge is detected on the int0 pin and is automatically cleared when the cpu vectors to the corresponding interrupt service routine. in this case, ie0 can also be cleared by software. if external interrupt 0 is configured to be level-sensitive (it0 = 0), ie0 is set when the int0# pin is 0 and cleared when the int0# pin is 1. in level- sensitive mode, software cannot write to ie0. tcon.0 it0 - interrupt 0 type select. int0 is detected on falling edge when it0 = 1; int0 is detected as a low level when it0 = 0.
c - 6 appendix c: 8051 hardware description ez-usb trm v1.9 c.2.5 mode 2 mode 2 operation is the same for timer 0 and timer 1. in mode 2, the timer is configured as an 8-bit counter, with automatic reload of the start value. the lsb register (tl0 or tl1) is the counter and the msb register (th0 or th1) stores the reload value. as illustrated in figure c-2., mode 2 counter control is the same as for mode 0 and mode 1. however, in mode 2, when tl n increments from ffh, the value stored in th n is reloaded into tl n . figure c-2. timer 0/1 - mode 2 tl0 (or tl1) 0 7 divide by 12 divide by 4 t0 (or t1) pin tr0 (or tr1) gate int0# pin (or int1# pin) 7 0 tf0 (or tf1) th0 (or th1) t0m (or t1m) reload int 0 1 0 1 to s er ia l por t (timer 1 only) clk24 clk c/ t
ez-usb trm v1.9 appendix c: 8051 hardware description c - 7 c.2.6 mode 3 in mode 3, timer 0 operates as two 8-bit counters and timer 1 stops counting and holds its value. as shown in figure c-3., tl0 is configured as an 8-bit counter controlled by the normal timer 0 control bits. tl0 can either count clk24 cycles (divided by 4 or by 12) or high-to- low transitions on t0 , as determined by the c/t bit. the gate function can be used to give counter enable control to the int0# pin. th0 functions as an independent 8-bit counter. however, th0 can only count clk24 cycles (divided by 4 or by 12). the timer 1 control and flag bits (tr1 and tf1) are used as the control and flag bits for th0. when timer 0 is in mode 3, timer 1 has limited usage because timer 0 uses the timer 1 control bit (tr1) and interrupt flag (tf1). timer 1 can still be used for baud rate generation and the timer 1 count values are still available in the tl1 and th1 registers. control of timer 1 when timer 0 is in mode 3 is through the timer 1 mode bits. to turn timer 1 on, set timer 1 to mode 0, 1, or 2. to turn timer 1 off, set it to mode 3. the timer 1 c/t bit and t1m bit are still available to timer 1. therefore, timer 1 can count clk24/4, clk24/12, or high-to-low transitions on the t1 pin. the timer 1 gate function is also available when timer 0 is in mode 3. figure c-3. timer 0 - mode 3 tl0 0 7 divide by 12 divide by 4 t0 pin tr0 gate int0# pin 7 0 tf0 th0 t0m int tr1 tf1 int 0 1 0 1 clk24 clk c/ t
c - 8 appendix c: 8051 hardware description ez-usb trm v1.9 c.2.7 timer rate control the default timer clock scheme for the 8051 timers is 12 clk24 cycles per increment, the same as in the standard 8051. however, in the 8051, the instruction cycle is 4 clk24 cycles. using the default rate (12 clocks per timer increment) allows existing application code with real-time dependencies, such as baud rate, to operate properly. however, applications that require fast timing can set the timers to increment every 4 clk24 cycles by setting bits in the clock control register (ckcon) at sfr location 8eh (see table c-4.). the ckcon bits that control the timer clock rates are: ckcon bitcounter/timer 5timer 2 4timer 1 3timer 0 when a ckcon register bit is set to 1, the associated counter increments at 4-clk24 intervals. when a ckcon bit is cleared, the associated counter increments at 12-clk24 intervals. the timer controls are independent of each other. the default setting for all three timers is 0 (12-clk24 intervals). these bits have no effect in counter mode. table c-4. ckcon register - srf 8eh bit function ckcon.7,6 reserved ckcon.5 t2m - timer 2 clock select. when t2m = 0, timer 2 uses clk24/12 (for compatibility with 80c32); when t2m = 1, timer 2 uses clk24/4. this bit has no effect when timer 2 is configured for baud rate generation. ckcon.4 t1m - timer 1 clock select. when t1m = 0, timer 1 uses clk24/12 (for compatibility with 80c32); when t1m = 1, timer 1 uses clk24/4. ckcon.3 t0m - timer 0 clock select. when t0m = 0, timer 0 uses clk24/12 (for compatibility with 80c32); when t0m = 1, timer 0 uses clk24/4. ckcon.2-0 md2, md1, md0 - control the number of cycles to be used for external movx instructions.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 9 c.2.8 timer 2 timer 2 runs only in 16-bit mode and offers several capabilities not available with timers 0 and 1. the modes available with timer 2 are: ? 16-bit timer/counter ? 16-bit timer with capture ? 16-bit auto-reload timer/counter ? baud rate generator the sfrs associated with timer 2 are: ? t2con - sfr c8h (table c-6.) ? rcap2l - sfr cah - used to capture the tl2 value when timer 2 is configured for capture mode, or as the lsb of the 16-bit reload value when timer 2 is configured for auto-reload mode. ? rcap2h - sfr cbh - used to capture the th2 value when timer 2 is configured for capture mode, or as the msb of the 16-bit reload value when timer 2 is configured for auto-reload mode. ? tl2 - sfr cch - lower 8 bits of the 16-bit count. ? th2 - sfr cdh - upper 8 bits of the 16-bit count. c.2.8.1 timer 2 mode control table c-5. summarizes how the sfr bits determine the timer 2 mode. table c-5. timer 2 mode control summary rclk tclk cp/rl 2 tr2 mode 0 0 1 1 16-bit timer/counter with capture 0 0 0 1 16-bit timer/counter with auto-reload 1 x x 1 baud rate generator x 1 x 1 baud rate generator xx x 0off x = dont care.
c - 10 appendix c: 8051 hardware description ez-usb trm v1.9 c.2.8.2 16-bit timer/counter mode figure c-4. illustrates how timer 2 operates in timer/counter mode with the optional capture feature. the c/t2 bit determines whether the 16-bit counter counts clk24 cycles (divided by 4 or 12), or high-to-low transitions on the t2 pin. the tr2 bit enables the counter. when the count increments from ffffh, the tf2 flag is set, and the t2out pin goes high for one clk24 cycle. table c-6. t2con register - sfr c8h bit function t2con.7 tf2 - timer 2 overflow flag. hardware will set tf2 when the timer 2 overflows from ffffh. tf2 must be cleared to 0 by the software. tf2 will only be set to a 1 if rclk and tclk are both cleared to 0. writing a 1 to tf2 forces a timer 2 interrupt if enabled. t2con.6 exf2 - timer 2 external flag. hardware will set exf2 when a reload or capture is caused by a high-to-low transition on the t2ex pin, and exen2 is set. exf2 must be cleared to 0 by the software. writing a 1 to exf2 forces a timer 2 interrupt if enabled. t2con.5 rclk - receive clock flag. determines whether timer 1 or timer 2 is used for serial port 0 timing of received data in serial mode 1 or 3. rclk =1 selects timer 2 overflow as the receive clock. rclk =0 selects timer 1 overflow as the receive clock. t2con.4 tclk - transmit clock flag. determines whether timer 1 or timer 2 is used for serial port 0 timing of transmit data in serial mode 1 or 3. rclk =1 selects timer 2 overflow as the transmit clock. rclk =0 selects timer 1 overflow as the transmit clock. t2con.3 exen2 - timer 2 external enable. exen2 = 1 enables capture or reload to occur as a result of a high-to-low transition on the t2ex pin, if timer 2 is not generating baud rates for the serial port. exen2 = 0 causes timer 2 to ignore all external events on the t2ex pin. t2con.2 tr2 - timer 2 run control flag. tr2 = 1 starts timer 2. tr2 = 0 stops timer 2. t2con.1 c/t2 - counter/timer select. c/t2 = 0 selects a timer function for timer 2. c/t2 = 1 selects a counter of falling transitions on the t2 pin. when used as a timer, timer 2 runs at 4 clocks per tick or 12 clocks per tick as programmed by ckcon.5, in all modes except baud rate generator mode. when used in baud rate generator mode, timer 2 runs at 2 clocks per tick, independent of the state of ckcon.5.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 11 c.2.8.3 6-bit timer/counter mode with capture the timer 2 capture mode (figure c-4.) is the same as the 16-bit timer/counter mode, with the addition of the capture registers and control signals. the cp/rl2 bit in the t2con sfr enables the capture feature. when cp/rl2 = 1, a high-to- low transition on the t2ex pin when exen2 = 1 causes the timer 2 value to be loaded into the capture registers rcap2l and rcap2h. t2con.0 cp/rl2 - capture/reload flag. when cp/rl2 =1,timer2 captures occur on high-to-low transitions of the t2ex pin, if exen2 = 1. when cp/rl 2 = 0, auto-reloads occur when timer 2 overflows or when high-to-low transitions occur on the t2ex pin, if exen2 = 1. if either rclk or tclk is set to 1, cp/rl2 will not function and timer 2 will operate in auto-reload mode following each overflow. figure c-4. timer 2 - timer/counter with capture table c-6. t2con register - sfr c8h bit function 0 7 divide by 12 divide by 4 clk24 t2 pin tr2 clk 7 0 exf2 t2m int rcap2l tl2 th2 rcap2h 8 15 8 15 exen2 t2ex pin capture tf2 0 1 0 1 c/ t2
c - 12 appendix c: 8051 hardware description ez-usb trm v1.9 c.2.8.4 16-bit timer/counter mode with auto-reload when cp/rl2 = 0, timer 2 is configured for the auto-reload mode illustrated in figure c-5.. control of counter input is the same as for the other 16-bit counter modes. when the count increments from ffffh, timer 2 sets the tf2 flag and the starting value is reloaded into tl2 and th2. the software must preload the starting value into the rcap2l and rcap2h registers. when timer 2 is in auto-reload mode, a reload can be forced by a high-to-low transition on the t2ex pin, if enabled by exen2 = 1. c.2.8.5 baud rate generator mode setting either rclk or tclk to 1 configures timer 2 to generate baud rates for serial port 0 in serial mode 1 or 3. in baud rate generator mode, timer 2 functions in auto-reload mode. however, instead of setting the tf2 flag, the counter overflow is used to generate a shift clock for the serial port function. as in normal auto-reload mode, the overflow also causes the preloaded start value in the rcap2l and rcap2h registers to be reloaded into the tl2 and th2 registers. when either tclk = 1 or rclk = 1, timer 2 is forced into auto-reload operation, regardless of the state of the cp/rl2 bit. when operating as a baud rate generator, timer 2 does not set the tf2 bit. in this mode, a timer 2 interrupt can only be generated by a high-to-low transition on the t2ex pin setting the exf2 bit, and only if enabled by exen2 = 1. figure c-5. timer 2 - timer/counter with auto reload 0 7 divide by 12 divide by 4 clk24 t2 pin tr2 clk 7 0 exf2 t2m int rcap2l tl2 th2 rcap2h 8 15 8 15 exen2 t2ex pin tf2 0 10 1 c/ t2
ez-usb trm v1.9 appendix c: 8051 hardware description c - 13 the counter time base in baud rate generator mode is clk24/2. to use an external clock source, set c/t2 to 1 and apply the desired clock source to the t2 pin. c.3 serial interface the 8051 core provides two serial ports. serial port 0 is identical in operation to the standard 8051 serial port. serial port 1 is identical to serial port 0, except that timer 2 cannot be used as the baud rate generator for serial port 1. each serial port can operate in synchronous or asynchronous mode. in synchronous mode, 8051 generates the serial clock and the serial port operates in half-duplex mode. in asynchronous mode, the serial port operates in full-duplex mode. in all modes, 8051 buffers received data in a holding register, enabling the uart to receive an incoming byte before the software has read the previous value. each serial port can operate in one of four modes, as outlined in table c-7.. figure c-6. timer 2 - baud rate generator mode 0 7 divide by 2 t2 pin tr2 7 0 exf2 timer 2 interrupt rcap2l tl2 th2 rcap2h 8 15 8 15 exen2 t2ex pin divide by 2 timer 1 overflow divide by 16 divide by 16 rx clock tx clock smod1 rclk tclk 0 0 0 0 1 1 1 1 clk clk24 c/ t2
c - 14 appendix c: 8051 hardware description ez-usb trm v1.9 the sfrs associated with the serial ports are: ? scon0 - sfr 98h - serial port 0 control (table c-8.). ? sbuf0 - sfr 99h - serial port 0 buffer. ? scon1 - sfr c0h - serial port 1 control (table c-9.). ? sbuf1 - sfr c1h - serial port 1 buffer. c.3.1 803x/805x compatibility the implementation of the serial interface is similar to that of the intel 8052. c.3.2 mode 0 serial mode 0 provides synchronous, half-duplex serial communication. for serial port 0, serial data output occurs on the rxd0out pin, serial data is received on the rxd0 pin, and the txd0 pin provides the shift clock for both transmit and receive. for serial port 1, the corresponding pins are rxd1out, rxd1, and txd1. the serial mode 0 baud rate is either clk24/12 or clk24/4, depending on the state of the sm2_0 bit (or sm2_1 for serial port 1). when sm2_0 = 0, the baud rate is clk24/12, when sm2_0 = 1, the baud rate is clk24/4. mode 0 operation is identical to the standard 8051. data transmission begins when an instruction writes to the sbuf0 (or sbuf1) sfr. the uart shifts the data, lsb first, at the selected baud rate, until the 8-bit value has been shifted out. mode 0 data reception begins when the ren_0 (or ren_1) bit is set and the ri_0 (or ri_1) bit is cleared in the corresponding scon sfr. the shift clock is activated and the uart shifts data in on each rising edge of the shift clock until 8 bits have been received. one table c-7. serial port modes mode sync/ async baud clock data bits start/stop 9th bit function 0 sync clk24/4 or clk24/12 8 none none 1async timer 1 or timer 2 1 8 1 start, 1 stop none 2 async clk24/32 or clk24/64 9 1 start, 1 stop 0, 1, parity 3async timer 1 or timer 2 1 9 1 start, 1 stop 0, 1, parity (1) timer 2 available for serial port 0 only.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 15 machine cycle after the 8th bit is shifted in, the ri_0 (or ri_1) bit is set and reception stops until the software clears the ri bit. figure c-7.through figure c-10.illustrate serial port mode 0 transmit and receive timing for both low-speed (clk24/12) and high-speed (clk24/4) operation. table c-8. scon0 register - sfr 98h bit function scon0.7 sm0_0 - serial port 0 mode bit 0. scon0.6 sm1_0 - serial port 0 mode bit 1, decoded as: sm0_0 sm1_0 mode 000 011 102 113 scon0.5 sm2_0 - multiprocessor communication enable. in modes 2 and 3, this bit enables the multiprocessor communication feature. if sm2_0 = 1 in mode 2 or 3, then ri_0 will not be activated if the received 9th bit is 0. if sm2_0=1 in mode 1, then ri_0 will only be activated if a valid stop is received. in mode 0, sm2_0 establishes the baud rate: when sm2_0=0, the baud rate is clk24/12; when sm2_0=1, the baud rate is clk24/4. scon0.4 ren_0 - receive enable. when ren_0=1, reception is enabled. scon0.3 tb8_0 - defines the state of the 9th data bit transmitted in modes 2 and 3. scon0.2 rb8_0 - in modes 2 and 3, rb8_0 indicates the state of the 9th bit received. in mode 1, rb8_0 indicates the state of the received stop bit. in mode 0, rb8_0 is not used. scon0.1 ti_0 - transmit interrupt flag. indicates that the transmit data word has been shifted out. in mode 0, ti_0 is set at the end of the 8th data bit. in all other modes, ti_0 is set when the stop bit is placed on the txd0 pin. ti_0 must be cleared by firmware. scon0.0 ri_0 - receive interrupt flag. indicates that serial data word has been received. in mode 0, ri_0 is set at the end of the 8th data bit. in mode 1, ri_0 is set after the last sample of the incoming stop bit, subject to the state of sm2_0. in modes 2 and 3, ri_0 is set at the end of the last sample of rb8_0. ri_0 must be cleared by firmware.
c - 16 appendix c: 8051 hardware description ez-usb trm v1.9 table c-9. scon1 register - sfr c0h bit function scon1.7 sm0_1 - serial port 1 mode bit 0. scon1.6 sm1_1 - serial port 1 mode bit 1, decoded as: sm0_1 sm1_1 mode 000 011 102 113 scon1.5 sm2_1 - multiprocessor communication enable. in modes 2 and 3, this bit enables the multiprocessor communication feature. if sm2_1 = 1 in mode 2 or 3, then ri_1 will not be activated if the received 9th bit is 0. if sm2_1=1 in mode 1, then ri_1 will only be activated if a valid stop is received. in mode 0, sm2_1 establishes the baud rate: when sm2_1=0, the baud rate is clk24/12; when sm2_1=1, the baud rate is clk24/4. scon1.4 ren_1 - receive enable. when ren_1=1, reception is enabled. scon1.3 tb8_1 - defines the state of the 9th data bit transmitted in modes 2 and 3. scon1.2 rb8_1 - in modes 2 and 3, rb8_0 indicates the state of the 9th bit received. in mode 1, rb8_1 indicates the state of the received stop bit. in mode 0, rb8_1 is not used. scon1.1 ti_1 - transmit interrupt flag. indicates that the transmit data word has been shifted out. in mode 0, ti_1 is set at the end of the 8th data bit. in all other modes, ti_1 is set when the stop bit is placed on the txd0 pin. ti_1 must be cleared by the software. scon1.0 ri_1 - receive interrupt flag. indicates that serial data word has been received. in mode 0, ri_1 is set at the end of the 8th data bit. in mode 1, ri_1 is set after the last sample of the incoming stop bit, subject to the state of sm2_1. in modes 2 and 3, ri_1 is set at the end of the last sample of rb8_1. ri_1 must be cleared by the software.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 17 figure c-7. serial port mode 0 receive timing - low speed operation figure c-8. serial port mode 0 receive timing - high speed operation clk24 d0 d1 d2 d3 d4 d5 d6 d7 ri txd0 rxd0 rxd0out psen ti d0 d1 d2 d3 d4 d5 d6 d7 clk24 ri txd0 rxd0 rxd0out psen ti
c - 18 appendix c: 8051 hardware description ez-usb trm v1.9 figure c-9. serial port mode 0 transmit timing - low speed operation figure c-10. serial port mode 0 transmit timing - high speed operation clk24 ri txd0 rxd0 rxd0out psen ti d0 d1 d2 d3 d4 d5 d6 d7 clk24 ri txd0 rxd0 rxd0out psen ti d0 d1 d2 d3 d4 d5 d6 d7
ez-usb trm v1.9 appendix c: 8051 hardware description c - 19 c.3.3 mode 1 mode 1 provides standard asynchronous, full-duplex communication, using a total of 10 bits: 1 start bit, 8 data bits, and 1 stop bit. for receive operations, the stop bit is stored in rb8_0 (or rb8_1). data bits are received and transmitted lsb first. c.3.3.1 mode 1 baud rate the mode 1 baud rate is a function of timer overflow. serial port 0 can use either timer 1 or timer 2 to generate baud rates. serial port 1 can only use timer 1. the two serial ports can run at the same baud rate if they both use timer 1, or different baud rates if serial port 0 uses timer 2 and serial port 1 uses timer 1. each time the timer increments from its maximum count (ffh for timer 1 or ffffh for timer 2), a clock is sent to the baud rate circuit. the clock is then divided by 16 to generate the baud rate. when using timer 1, the smod0 (or smod1) bit selects whether or not to divide the timer 1 rollover rate by 2. therefore, when using timer 1, the baud rate is determined by the equation: smod0 is sfr bit pcon.7; smod1 is sfr bit eicon.7. when using timer 2, the baud rate is determined by the equation: to use timer 1 as the baud rate generator, it is best to use timer 1 mode 2 (8-bit counter with auto-reload), although any counter mode can be used. the timer 1 reload is stored in the th1 register, which makes the complete formula for timer 1: x timer 1 overflow baud rate = 32 2 smodx timer 2 overflow baud rate = 16 x baud rate = 32 2 smodx 12 x (256 - th1) clk24
c - 20 appendix c: 8051 hardware description ez-usb trm v1.9 the 12 in the denominator in the above equation can be changed to 4 by setting the t1m bit in the ckcon sfr. to derive the required th1 value from a known baud rate (when tm1 = 0), use the equation: you can also achieve very low serial port baud rates from timer 1 by enabling the timer 1 interrupt, configuring timer 1 to mode 1, and using the timer 1 interrupt to initiate a 16-bit software reload. table c-10. lists sample reload values for a variety of common serial port baud rates. note that more accurate baud rates are achieved by using timer 2 as the baud rate generator (next section). to use timer 2 as the baud rate generator, configure timer 2 in auto-reload mode and set the tclk and/or rclk bits in the t2con sfr. tclk selects timer 2 as the baud rate generator for the transmitter; rclk selects timer 2 as the baud rate generator for the receiver. the 16-bit reload value for timer 2 is stored in the rcap2l and rca2h sfrs, which makes the equation for the timer 2 baud rate: table c-10. timer 1 reload values for common serial port mode 1 baud rates nominal rate 24 mhz divisor reload va lue actual rate error 57600 6 fa 62500 8.5% 38400 10 f6 37500 -2.3% 28800 13 f3 28846 +0.16% 19200 20 ec 18750 -2.3% 9600 39 d9 9615 +0.16% 4800 78 b2 4807 +0.15% 2400 156 64 2403 +.13% settings: smod =1, c/t =0, timer1 mode=2, tim=1 note: using rates that are off by 2.3% or more will not work in all systems. x th1 = 2 smodx clk24 384 x baud rate 256 -
ez-usb trm v1.9 appendix c: 8051 hardware description c - 21 where rcap2h,rcap2l is the content of rcap2h and rcap2l taken as a 16-bit unsigned number. the 32 in the denominator is the result of clk24 being divided by 2 and the timer 2 overflow being divided by 16. setting tclk or rclk to 1 automatically causes clk24 to be divided by 2, as shown in figure c-6., instead of the 4 or 12 determined by the t2m bit in the ckcon sfr. to derive the required rcap2h and rcap2l values from a known baud rate, use the equation: when either rclk or tclk is set, the tf2 flag will not be set on a timer 2 roll over, and the t2ex reload trigger is disabled. table c-11. timer 2 reload values for common serial port mode 1 baud rates nominal rate c/t2 diviso r reload val actual rate error 57600 0 13 f3 57692.31 0.16% 38400 0 20 ec 37500 -2.34% 28800 0 26 e6 28846.15 0.16% 19200 0 39 d9 19230.77 0.16% 9600 0 78 b2 9615.385 0.16% 4800 0 156 64 4807.692 0.16% 2400 0 312 fec8 2403.846 0.16% note: using rates that are off by 2.3% or more will not work in all systems. baud rate = 32 x (65536 - rcap2h,rcap2l) clk24 rcap2h,rcap2l = clk24 32 x baud rate 65536 -
c - 22 appendix c: 8051 hardware description ez-usb trm v1.9 c.3.3.2 mode 1 transmit figure c-11. illustrates the mode 1 transmit timing. in mode 1, the uart begins transmitting after the first roll over of the divide-by-16 counter after the software writes to the sbuf0 (or sbuf1) register. the uart transmits data on the txd0 (or txd1) pin in the following order: start bit, 8 data bits (lsb first), stop bit. the ti_0 (or ti_1) bit is set 2 clk24 cycles after the stop bit is transmitted. c.3.3.3 mode 1 receive figure c-12. illustrates the mode 1 receive timing. reception begins at the falling edge of a start bit received on the rxd0 (or rxd1) pin, when enabled by the ren_0 (or ren_1) bit. for this purpose, the rxd0 (or rxd1) pin is sampled 16 times per bit for any baud rate. when a falling edge of a start bit is detected, the divide-by-16 counter used to generate the receive clock is reset to align the counter roll over to the bit boundaries. for noise rejection, the serial port establishes the content of each received bit by a majority decision of 3 consecutive samples in the middle of each bit time. this is especially true for the start bit. if the falling edge on the rxd0 (or rxd1) pin is not verified by a majority decision of 3 consecutive samples (low), then the serial port stops reception and waits for another falling edge on the rxd0 (or rxd1) pin. at the middle of the stop bit time, the serial port checks for the following conditions: ? ri_0 (or ri_1) = 0, and ? if sm2_0 (or sm2_1) = 1, the state of the stop bit is 1. (if sm2_0 (or sm2_1) = 0, the state of the stop bit doesnt matter.) if the above conditions are met, the serial port then writes the received byte to the sbuf0 (or sbuf1) register, loads the stop bit into rb8_0 (or rb8_1), and sets the ri_0 (or ri_1) bit. if the above conditions are not met, the received data is lost, the sbuf register and rb8 bit are not loaded, and the ri bit is not set. after the middle of the stop bit time, the serial port waits for another high-to-low transition on the (rxd0 or rxd1) pin. mode 1 operation is identical to that of the standard 8051 when timers 1 and 2 use clk24/12 (the default).
ez-usb trm v1.9 appendix c: 8051 hardware description c - 23 figure c-11. serial port 0 mode 1 transmit timing figure c-12. serial port 0 mode 1 receive timing write to sbuf0 ri_0 txd0 rxd0 rxd0out shift tx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start ri_0 txd0 rxd0 rxd0out shift rx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start bit detector sampling
c - 24 appendix c: 8051 hardware description ez-usb trm v1.9 c.3.4 mode 2 mode 2 provides asynchronous, full-duplex communication, using a total of 11 bits: 1 start bit, 8 data bits, a programmable 9th bit, and 1 stop bit. the data bits are transmitted and received lsb first. for transmission, the 9th bit is determined by the value in tb8_0 (or tb8_1). to use the 9th bit as a parity bit, move the value of the p bit (sfr psw.0) to tb8_0 (or tb8_1). the mode 2 baud rate is either clk24/32 or clk24/64, as determined by the smod0 (or smod1) bit. the formula for the mode 2 baud rate is: mode 2 operation is identical to the standard 8051. c.3.4.1 mode 2 transmit figure c-13. illustrates the mode 2 transmit timing. transmission begins after the first roll over of the divide-by-16 counter following a software write to sbuf0 (or sbuf1). the uart shifts data out on the txd0 (or txd1) pin in the following order: start bit, data bits (lsb first), 9th bit, stop bit. the ti_0 (or ti_1) bit is set when the stop bit is placed on the txd0 (or txd1) pin. c.3.4.2 mode 2 receive figure c-14. illustrates the mode 2 receive timing. reception begins at the falling edge of a start bit received on the rxd0 (or rxd1) pin, when enabled by the ren_0 (or ren_1) bit. for this purpose, the rxd0 (or rxd1) pin is sampled 16 times per bit for any baud rate. when a falling edge of a start bit is detected, the divide-by-16 counter used to generate the receive clock is reset to align the counter roll over to the bit boundaries. for noise rejection, the serial port establishes the content of each received bit by a majority decision of 3 consecutive samples in the middle of each bit time. this is especially true for the start bit. if the falling edge on the rxd0 (or rxd1) pin is not verified by a majority decision of 3 consecutive samples (low), then the serial port stops reception and waits for another falling edge on the rxd0 (or rxd1) pin. at the middle of the stop bit time, the serial port checks for the following conditions: ? ri_0 (or ri_1) = 0, and ? if sm2_0 (or sm2_1) = 1, the state of the stop bit is 1. (if sm2_0 (or sm2_1) = 0, the state of the stop bit doesnt matter.) x baud rate = 2 smodx clk24 64
ez-usb trm v1.9 appendix c: 8051 hardware description c - 25 if the above conditions are met, the serial port then writes the received byte to the sbuf0 (or sbuf1) register, loads the stop bit into rb8_0 (or rb8_1), and sets the ri_0 (or ri_1) bit. if the above conditions are not met, the received data is lost, the sbuf register and rb8 bit are not loaded, and the ri bit is not set. after the middle of the stop bit time, the serial port waits for another high-to-low transition on the rxd0 ( or rxd1) pin. figure c-13. serial port 0 mode 2 transmit timing figure c-14. serial port 0 mode 2 receive timing ri_0 txd0 rxd0 rxd0out shift tx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start write to sbuf0 tb8 ri_0 txd0 rxd0 rxd0out shift rx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start rb8 bit detector sampling
c - 26 appendix c: 8051 hardware description ez-usb trm v1.9 c.3.5 mode 3 mode 3 provides asynchronous, full-duplex communication, using a total of 11 bits: 1 start bit, 8 data bits, a programmable 9th bit, and 1 stop bit. the data bits are transmitted and received lsb first. the mode 3 transmit and operations are identical to mode 2. the mode 3 baud rate generation is identical to mode 1. that is, mode 3 is a combination of mode 2 protocol and mode 1 baud rate. figure c-15.illustrates the mode 3 transmit timing. figure c-16.illustrates the mode 3 receive timing. mode 3 operation is identical to that of the standard 8051 when timers 1 and 2 use clk24/12 (the default). figure c-15. serial port 0 mode 3 transmit timing figure c-16. serial port 0 mode 3 receive timing ri_0 txd0 rxd0 rxd0out shift tx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start write to sbuf0 tb8 ri_0 txd0 rxd0 rxd0out shift rx clk ti_0 d0 d1 d2 d3 d4 d5 d6 d7 stop start rb8 bit detector sampling
ez-usb trm v1.9 appendix c: 8051 hardware description c - 27 c.3.6 multiprocessor communications the multiprocessor communication feature is enabled in modes 2 and 3 when the sm2 bit is set in the scon sfr for a serial port (sm2_0 for serial port 0, sm2_1 for serial port 1). in multiprocessor communication mode, the 9th bit received is stored in rb8_0 (or rb8_1) and, after the stop bit is received, the serial port interrupt is activated only if rb8_0 (or rb8_1) = 1. a typical use for the multiprocessor communication feature is when a master wants to send a block of data to one of several slaves. the master first transmits an address byte that identifies the target slave. when transmitting an address byte, the master sets the 9th bit to 1; for data bytes, the 9th bit is 0. with sm2_0 (or sm2_1) = 1, no slave will be interrupted by a data byte. however, an address byte interrupts all slaves so that each slave can examine the received address byte to determine whether that slave is being addressed. address decoding must be done by software during the interrupt service routine. the addressed slave clears its sm2_0 (or sm2_1) bit and prepares to receive the data bytes. the slaves that are not being addressed leave the sm2_0 (or sm2_1) bit set and ignore the incoming data bytes. c.3.7 interrupt sfrs the following sfrs are associated with interrupt control: ? ie - sfr a8h (table c-12.) ? ip - sfr b8h (table c-13.) ? exif - sfr 91h (table c-14.) ? eicon - sfr d8h (table c-15.) ? eie - sfr e8h (table c-16.) ? eip - sfr f8h (table c-17.) the ie and ip sfrs provide interrupt enable and priority control for the standard interrupt unit, as with the standard 8051. additionally, these sfrs provide control bits for the serial port 1 interrupt. these bits (es1 and ps1) are available only when the extended interrupt unit is implemented (ext_intr=1). otherwise, they are read as 0. bits es0, es1, et2, ps0, ps1, and pt2 are present, but not used, when the corresponding module is not implemented. the exif, eicon, eie and eip registers provide flags, enable control, and priority control for the optional extended interrupt unit.
c - 28 appendix c: 8051 hardware description ez-usb trm v1.9 table c-12. ie register - sfr a8h bit function ie.7 ea - global interrupt enable. controls masking of all interrupts except usb wakeup (resume). ea = 0 disables all interrupts except usb wakeup. when ea = 1, interrupts are enabled or masked by their individual enable bits. ie.6 es1 - enable serial port 1 interrupt. es1 = 0 disables serial port 1 interrupts (ti_1 and ri_1). es1 = 1 enables interrupts generated by the ti_1 or ti_1 flag. ie.5 et2 - enable timer 2 interrupt. et2 = 0 disables timer 2 interrupt (tf2). et2=1 enables interrupts generated by the tf2orexf2flag. ie.4 es0 - enable serial port 0 interrupt. es0 = 0 disables serial port 0 interrupts (ti_0 and ri_0). es0=1 enables interrupts generated by the ti_0 or ri_0 flag. ie.3 et1 - enable timer 1 interrupt. et1 = 0 disables timer 1 interrupt (tf1). et1=1 enables interrupts generated by the tf1 flag. ie.2 ex1 - enable external interrupt 1. ex1 = 0 disables external interrupt 1 (int1). ex1=1 enables interrupts generated by the int1# pin. ie.1 et0 - enable timer 0 interrupt. et0 = 0 disables timer 0 interrupt (tf0). et0=1 enables interrupts generated by the tf0 flag. ie.0 ex0 - enable external interrupt 0. ex0 = 0 disables external interrupt 0 (int0). ex0=1 enables interrupts generated by the int0# pin.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 29 table c-13. ip register - sfr b8h bit function ip.7 reserved. read as 1. ip.6 ps1 - serial port 1 interrupt priority control. ps1=0 sets serial port 1 interrupt (ti_1 or ri_1) to low priority. ps1=1 sets serial port 1 interrupt to high priority. ip.5 pt2 - timer 2 interrupt priority control. pt2=0 sets timer 2 interrupt (tf2) to low priority. pt2=1 sets timer 2 interrupt to high priority. ip.4 ps0 - serial port 0 interrupt priority control. ps0=0 sets serial port 0 interrupt (ti_0 or ri_0) to low priority. ps0=1 sets serial port 0 interrupt to high priority. ip.3 pt2 - timer 1 interrupt priority control. pt1 = 0 sets timer 1 interrupt (tf1) to low priority. pt1=1 sets timer 1 interrupt to high priority. ip.2 px1 - external interrupt 1 priority control. px 1= 0 sets external interrupt 1 (int1) to low priority. pt1 = 1 sets externalinterrupt1tohighpriority. ip.1 pt0 - timer 0 interrupt priority control. pt0 = 0 sets timer 0 interrupt (tf0) to low priority. pt0=1 sets timer 0 interrupt to high priority. ip.0 px0 - external interrupt 0 priority control. px0 = 0 sets external interrupt 0 (int0) to low priority. px0=1 sets externalinterrupt0tohighpriority.
c - 30 appendix c: 8051 hardware description ez-usb trm v1.9 table c-14. exif register - sfr 91h bit function exif.7 ie5 - external interrupt 5 flag. ie 5= 1 indicates a falling edge was detected at the int5# pin. ie5 must be cleared by software. setting ie5 in software generates an interrupt, if enabled. exif.6 ie4 - external interrupt 4 flag. ie4 indicates a rising edge was detected at the int4 pin. ie4 must be cleared by software. setting ie4 in software generates an interrupt, if enabled. exif.5 i2cint - external interrupt 3 flag. the int3 interrupt is internally connected to the ez-usb i 2 c controller and renamed i2cint. i2cint = 1 indicates an i 2 c interrupt. i2cint must be cleared by software. setting i2cint in software generates an interrupt, if enabled. exif.4 usbint - external interrupt 2 flag. the int2 interrupt is internally connected to the ez-usb interrupt and renamed usbint. usbint = 1 indicates an usb interrupt. usbint must be cleared by software. setting usbint in software generates an interrupt, if enabled. exif.3 reserved. read as 1. exif.2-0 reserved. read as 0.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 31 table c-15. eicon register - sfr d8h bit function eicon.7 smod1 - serial port 1 baud rate doubler enable. when smod1 = 1 the baud rate for serial port is doubled. eicon.6 reserved. read as 1. eicon.5 eresi - enable resume interrupt. eresi = 0 disables resume interrupt (resi). eresi = 1 enables interrupts generated by the resume event. eicon.4 resi - wakeup interrupt flag. eicon.4 = 1 indicates a negative transition was detected at the wakeup# pin, or that usb has activity resumed from the suspended state. eicon.4 = 1 must be cleared by software before exiting the interrupt service routine, otherwise the interrupt occurs again. setting eicon.4=1 in software generates a wakeup interrupt, if enabled. eicon.3 int6 - external interrupt 6. when int6 = 1, the int6 pin has detected a low to high transition. int6 will remain active until cleared by writing a 0 to this bit. setting this bit in software generates an int6 interrupt in enabled. eicon.2-0 reserved. read as 0.
c - 32 appendix c: 8051 hardware description ez-usb trm v1.9 table c-16. eie register - sfr e8h bit function eie.7-5 reserved. read as 1. eie.4 ex6 - enable external interrupt 6. ex6 = 0 disables external interrupt 6 (int6). ex6 = 1 enables interrupts generated by the int6 pin. eie.3 ex5 - enable external interrupt 5. ex5 = 0 disables external interrupt 5 (int5). ex5 = 1 enables interrupts generated by the int5# pin. eie.2 ex4 - enable external interrupt 4. ex4 = 0 disables external interrupt 4 (int4). ex4 = 1 enables interrupts generated by the int4 pin. eie.1 ei2c - enable external interrupt 3. ei2c = 0 disables external interrupt 3 (int3). ei2c = 1 enables interrupts generated by the i 2 c interface. eie.0 eusb - enable usb interrupt. eusb = 0 disables usb interrupts. eusb = 1 enables interrupts generated by the usb interface.
ez-usb trm v1.9 appendix c: 8051 hardware description c - 33 c.4 interrupt processing when an enabled interrupt occurs, the 8051 core vectors to the address of the interrupt service routine (isr) associated with that interrupt, as listed in table c-18.. the 8051 core executes the isr to completion unless another interrupt of higher priority occurs. each isr ends with a reti (return from interrupt) instruction. after executing the reti , the cpu returns to the next instruction that would have been executed if the interrupt had not occurred. an isr can only be interrupted by a higher priority interrupt. that is, an isr for a low-level interrupt can only be interrupted by high-level interrupt. an isr for a high-level interrupt can only be interrupted by the resume interrupt. the 8051 core always completes the instruction in progress before servicing an interrupt. if the instruction in progress is reti , or a write access to any of the ip, ie, eip, or eie sfrs, the 8051 core completes one additional instruction before servicing the interrupt. c.4.1 interrupt masking the ea bit in the ie sfr (ie.7) is a global enable for all interrupts except the usb wakeup (resume) interrupt. when ea = 1, each interrupt is enabled or masked by its individual enable bit. when ea = 0, all interrupts are masked, except the usb wakeup interrupt. table c-17. eip register - sfr f8h bit function eip.7-5 reserved. read as 1. eip.4 px6 - external interrupt 6 priority control. px6 = 0 sets external interrupt 6 (int6) to low priority. px6 = 1 sets externalinterrupt6tohighpriority. eip.3 px5 - external interrupt 5 priority control. px5 = 0 sets external interrupt 5 (int5#) to low priority. px5=1 sets externalinterrupt5tohighpriority. eip.2 px4 - external interrupt 4 priority control. px4 = 0 sets external interrupt 4 (int4) to low priority. px4=1 sets externalinterrupt4tohighpriority. eip.1 pi2c - external interrupt 3 priority control. pi2c = 0 sets i 2 c interrupt to low priority. pi2c=1 sets i 2 c interrupt to high priority. eip.0 pusb - external interrupt 2 priority control. pusb = 0 sets usb interrupt to low priority. pusb=1 sets usb interrupt to high priority.
c - 34 appendix c: 8051 hardware description ez-usb trm v1.9 table c-19. provides a summary of interrupt sources, flags, enables, and priorities. c.4.2 interrupt priorities there are two stages of interrupt priority assignment, interrupt level and natural priority. the interrupt level (highest, high, or low) takes precedence over natural priority. the usb wakeup interrupt, if enabled, always has highest priority and is the only interrupt that can have highest priority. all other interrupts can be assigned either high or low priority. in addition to an assigned priority level (high or low), each interrupt also has a natural priority, as listed in table c-18.. simultaneous interrupts with the same priority level (for example, both high) are resolved according to their natural priority. for example, if int0 and int2 are both programmed as high priority, int0 takes precedence due to its higher natural priority. once an interrupt is being serviced, only an interrupt of higher priority level can interrupt the service routine of the interrupt currently being serviced. table c-18. interrupt natural vectors and priorities interrupt description natural priority interrupt vec to r resume usb wakeup (resume) interrupt 0 33h int0 external interrupt 0 1 03h tf0 timer 0 interrupt 2 0bh int1 external interrupt 1 3 13h tf1 timer 1 interrupt 4 1bh ti_0 or ri_0 serial port 0 interrupt 5 23h tf2 or exf2 timer 2 interrupt 6 2bh ti_1 or ri_1 serial port 1 interrupt 7 3bh int2 usb interrupt 8 43h int3 i 2 c interrupt 94bh int4 external interrupt 4 4 53h int5 external interrupt 5 11 5bh int6 external interrupt 6 12 63h
ez-usb trm v1.9 appendix c: 8051 hardware description c - 35 c.4.3 interrupt sampling the internal timers and serial ports generate interrupts by setting their respective sfr interrupt flag bits. external interrupts are sampled once per instruction cycle. int0 and int1 are both active low and can be programmed to be either edge-sensitive or level-sensitive, through the it0 and it1 bits in the tcon sfr. for example, when it0 = 0, int0 is level-sensitive and the 8051 core sets the ie0 flag when the int0# pin is sampled low. when it0 = 1, int0 is edge-sensitive and the 8051 sets the ie0 flag when the int0# pin is sampled high then low on consecutive samples. the remaining five interrupts (int 4-6, usb & i 2 c interrupts) are edge-sensitive only. int6 and int4 are active high and int5 is active low. to ensure that edge-sensitive interrupts are detected, the corresponding ports should be held high for 4 clk24 cycles and then low for 4 clk24 cycles. level-sensitive interrupts are not table c-19. interrupt flags, enables, and priority control interrupt description flag enable priority control resume resume interrupt eicon.4 eicon.5 n/a int0 external interrupt 0 tcon.1 ie.0 ip.0 tf0 timer 0 interrupt tcon.5 ie.1 ip.1 int1 external interrupt 1 tcon.3 ie.2 ip.2 tf1 timer 1 interrupt tcon.7 ie.3 ip.3 ti_0 or ri_0 serial port 0 transmit or receive scon0.0 (ri.0), scon0.1 (ti_0) ie.4 ip.4 tf2orexf2 timer2interrupt t2con.7(tf2), t2con.6 (exf2) ie.5 ip.5 ti_1 or ri_1 serial port 1 transmit or receive scon1.0 (ri_1), scon1.1 (ti_1) ie.6 ip.6 usb usb interrupt exif.4 eie.0 eip.0 i 2 ci 2 c interrupt exit.5 eie.1 eip.1 int4 external interrupt 4 exif.6 eie.2 eip.2 int5 external interrupt 5 exif.7 eie.3 eip.3 int6 external int 6 eicon.3 eie.4 eip.4
c - 36 appendix c: 8051 hardware description ez-usb trm v1.9 latched and must remain active until serviced. c.4.4 interrupt latency interrupt response time depends on the current state of the 8051. the fastest response time is 5 instruction cycles: 1 to detect the interrupt, and 4 to perform the lcall to the isr. the maximum latency (13 instruction cycles) occurs when the 8051 is currently executing a reti instructionfollowedbya mul or div instruction. the 13 instruction cycles in this case are: 1 to detect the interrupt, 3 to complete the reti , 5 to execute the div or mul , and 4 to execute the lcall to the isr. for the maximum latency case, the response time is 13 x 4 = 52 clk24 cycles. c.4.5 single-step operation the 8051 interrupt structure provides a way to perform single-step program execution. when exiting an isr with an reti instruction, the 8051 will always execute at least one instruction of the task program. therefore, once an isr is entered, it cannot be re-entered until at least one program instruction is executed. to perform single-step execution, program one of the external interrupts (for example,int0) to be level-sensitive and write an isr for that interrupt the terminates as follows: jnb tcon.1,$ ; wait for high on int0# pin jb tcon.1,$ ; wait for low on int0# pin reti ; return for isr the cpu enters the isr when the int0# pin goes low, then waits for a pulse on int0#. each time int0# is pulsed, the cpu exits the isr, executes one program instruction, then re-enters the isr. c.5 reset the 8051 reset pin is internally connected to an ez-usb register bit that is controllable through the usb host. see chapter 10, "ez-usb resets" for details. c.6 power saving modes c.6.1 idle mode an instruction that sets the idle bit (pcon.0) causes the 8051 to enter idle mode when that instruction completes. in idle mode, cpu processing is suspended, and internal registers maintain their current data. when the 8051 core is in idle, the ez-usb core enters suspend
ez-usb trm v1.9 appendix c: 8051 hardware description c - 37 mode and shuts down the 24 mhz oscillator. see chapter 11, "ez-usb power management" for a full description of the suspend/resume process. table c-20. pcon register - sfr 87h bit function pcon.7 smod0 - serial port 0 baud rate double enable. when smod0 = 1, the baud rate for serial port 0 is doubled. pcon.6-4 reserved. pcon.3 gf1 - general purpose flag 1. bit-addressable, general purpose flag for software control. pcon.2 gf0 - general purpose flag 0. bit-addressable, general purpose flag for software control. pcon.1 this bit should always be set to 0. pcon.0 idle - idle mode select. setting the idle bit places the 8051 in idle mode.
c - 38 appendix c: 8051 hardware description ez-usb trm v1.9


▲Up To Search▲   

 
Price & Availability of AN2135S

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X